about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-07-28 01:16:30 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2013-08-04 19:46:52 +1000
commit8407ec9fedccdd410dee2bca67651ce245ed5cd3 (patch)
tree1169ef9f908506cbdfe415bbfe1d269f4afea6ec /src/libstd
parent44acdad5f8974206d871bb1134f67368bdb236ee (diff)
downloadrust-8407ec9fedccdd410dee2bca67651ce245ed5cd3.tar.gz
rust-8407ec9fedccdd410dee2bca67651ce245ed5cd3.zip
syntax: make #[deriving(TotalOrd)] lazy.
Previously it would call:

  f(sf1.cmp(&of1), f(sf2.cmp(&of2), ...))

(where s/of1 = 'self/other field 1', and f was
std::cmp::lexical_ordering)

This meant that every .cmp subcall got evaluated when calling a derived
TotalOrd.cmp.

This corrects this to use

   let test = sf1.cmp(&of1);
   if test == Equal {
      let test = sf2.cmp(&of2);
      if test == Equal {
        // ...
      } else {
        test
      }
   } else {
     test
   }

This gives a lexical ordering by short-circuiting on the first comparison
that is not Equal.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/cmp.rs1
1 files changed, 0 insertions, 1 deletions
diff --git a/src/libstd/cmp.rs b/src/libstd/cmp.rs
index 43a632562b2..b66f89e8341 100644
--- a/src/libstd/cmp.rs
+++ b/src/libstd/cmp.rs
@@ -153,7 +153,6 @@ pub fn cmp2<A:TotalOrd,B:TotalOrd>(
 Return `o1` if it is not `Equal`, otherwise `o2`. Simulates the
 lexical ordering on a type `(int, int)`.
 */
-// used in deriving code in libsyntax
 #[inline]
 pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering {
     match o1 {