@@ -530,54 +530,38 @@ pub fn eq(a: &~str, b: &~str) -> bool {
530
530
eq_slice ( * a, * b)
531
531
}
532
532
533
- #[ inline]
534
- fn cmp ( a : & str , b : & str ) -> Ordering {
535
- let low = uint:: min ( a. len ( ) , b. len ( ) ) ;
536
-
537
- for uint:: range( 0 , low) |idx| {
538
- match a[ idx] . cmp ( & b[ idx] ) {
539
- Greater => return Greater ,
540
- Less => return Less ,
541
- Equal => ( )
542
- }
543
- }
544
-
545
- a. len ( ) . cmp ( & b. len ( ) )
546
- }
547
-
548
533
#[ cfg( not( test) ) ]
549
534
impl < ' self > TotalOrd for & ' self str {
550
535
#[ inline]
551
- fn cmp ( & self , other : & & ' self str ) -> Ordering { cmp ( * self , * other) }
536
+ fn cmp ( & self , other : & & ' self str ) -> Ordering {
537
+ for self . bytes_iter( ) . zip( other. bytes_iter( ) ) . advance |( s_b, o_b) | {
538
+ match s_b. cmp( & o_b) {
539
+ Greater => return Greater ,
540
+ Less => return Less ,
541
+ Equal => ( )
542
+ }
543
+ }
544
+
545
+ self . len ( ) . cmp ( & other. len ( ) )
546
+ }
552
547
}
553
548
554
549
#[ cfg ( not ( test) ) ]
555
550
impl TotalOrd for ~str {
556
551
#[ inline]
557
- fn cmp ( & self , other : & ~str ) -> Ordering { cmp ( * self , * other) }
552
+ fn cmp( & self , other: & ~str) -> Ordering { self . as_slice ( ) . cmp ( & other. as_slice ( ) ) }
558
553
}
559
554
560
555
#[ cfg( not( test) ) ]
561
556
impl TotalOrd for @str {
562
557
#[ inline]
563
- fn cmp ( & self , other : & @str ) -> Ordering { cmp ( * self , * other) }
558
+ fn cmp ( & self , other : & @str ) -> Ordering { self . as_slice ( ) . cmp ( & other. as_slice ( ) ) }
564
559
}
565
560
566
561
/// Bytewise slice less than
567
562
#[ inline]
568
563
fn lt ( a : & str , b : & str ) -> bool {
569
- let ( a_len, b_len) = ( a. len ( ) , b. len ( ) ) ;
570
- let end = uint:: min ( a_len, b_len) ;
571
-
572
- let mut i = 0 ;
573
- while i < end {
574
- let ( c_a, c_b) = ( a[ i] , b[ i] ) ;
575
- if c_a < c_b { return true ; }
576
- if c_a > c_b { return false ; }
577
- i += 1 ;
578
- }
579
-
580
- return a_len < b_len;
564
+ a. cmp ( & b) == Less
581
565
}
582
566
583
567
/// Bytewise less than or equal
0 commit comments