@@ -775,14 +775,13 @@ fn each_split_within<'a>(ss: &'a str, lim: uint, it: |&'a str| -> bool)
775
775
let mut lim = lim;
776
776
777
777
let mut cont = true;
778
- let slice: || = || { cont = it(ss.slice(slice_start, last_end)) };
779
778
780
779
// if the limit is larger than the string, lower it to save cycles
781
780
if lim >= fake_i {
782
781
lim = fake_i;
783
782
}
784
783
785
- let machine: |(uint, char)| -> bool = |(i, c)| {
784
+ let machine: |&mut bool, (uint, char)| -> bool = |cont, (i, c)| {
786
785
let whitespace = if ::std::char::is_whitespace(c) { Ws } else { Cr };
787
786
let limit = if (i - slice_start + 1) <= lim { UnderLim } else { OverLim };
788
787
@@ -794,24 +793,49 @@ fn each_split_within<'a>(ss: &'a str, lim: uint, it: |&'a str| -> bool)
794
793
(B, Cr, OverLim) if (i - last_start + 1) > lim
795
794
=> fail!(" word starting with { } longer than limit!",
796
795
ss. slice ( last_start, i + 1 ) ) ,
797
- ( B , Cr , OverLim ) => { slice( ) ; slice_start = last_start; B }
798
- ( B , Ws , UnderLim ) => { last_end = i; C }
799
- ( B , Ws , OverLim ) => { last_end = i; slice ( ) ; A }
800
-
801
- ( C , Cr , UnderLim ) => { last_start = i; B }
802
- ( C , Cr , OverLim ) => { slice ( ) ; slice_start = i; last_start = i; last_end = i; B }
803
- ( C , Ws , OverLim ) => { slice ( ) ; A }
804
- ( C , Ws , UnderLim ) => { C }
796
+ ( B , Cr , OverLim ) => {
797
+ * cont = it ( ss. slice ( slice_start, last_end) ) ;
798
+ slice_start = last_start;
799
+ B
800
+ }
801
+ ( B , Ws , UnderLim ) => {
802
+ last_end = i;
803
+ C
804
+ }
805
+ ( B , Ws , OverLim ) => {
806
+ last_end = i;
807
+ * cont = it ( ss. slice ( slice_start, last_end) ) ;
808
+ A
809
+ }
810
+
811
+ ( C , Cr , UnderLim ) => {
812
+ last_start = i;
813
+ B
814
+ }
815
+ ( C , Cr , OverLim ) => {
816
+ * cont = it ( ss. slice ( slice_start, last_end) ) ;
817
+ slice_start = i;
818
+ last_start = i;
819
+ last_end = i;
820
+ B
821
+ }
822
+ ( C , Ws , OverLim ) => {
823
+ * cont = it ( ss. slice ( slice_start, last_end) ) ;
824
+ A
825
+ }
826
+ ( C , Ws , UnderLim ) => {
827
+ C
828
+ }
805
829
} ;
806
830
807
- cont
831
+ * cont
808
832
} ;
809
833
810
- ss. char_indices ( ) . advance ( |x| machine ( x) ) ;
834
+ ss. char_indices ( ) . advance ( |x| machine ( & mut cont , x) ) ;
811
835
812
836
// Let the automaton 'run out' by supplying trailing whitespace
813
837
while cont && match state { B | C => true , A => false } {
814
- machine ( ( fake_i, ' ' ) ) ;
838
+ machine ( & mut cont , ( fake_i, ' ' ) ) ;
815
839
fake_i += 1 ;
816
840
}
817
841
return cont;
0 commit comments