@@ -107,11 +107,9 @@ impl SpanIter {
107
107
///
108
108
/// * intersect: the end of span `A`
109
109
fn partition_spans_at ( & mut self , intersect : usize ) {
110
- let first_partitioned_span = self . spans [ self . index ] ;
111
-
112
110
let mut i = self . index ;
113
111
while let Some ( span) = self . spans . get_mut ( i) {
114
- if span. start != self . cursor || span. end < intersect {
112
+ if span. start != self . cursor || span. end <= intersect {
115
113
break ;
116
114
}
117
115
@@ -123,30 +121,23 @@ impl SpanIter {
123
121
i += 1 ;
124
122
}
125
123
126
- let num_partitioned_spans = i - self . index ;
127
-
128
124
// When spans are partioned, the span Vec may need to be re-sorted
129
125
// because the `span.start` may now be greater than some `span.start`
130
126
// later in the Vec. This is not a classic "sort": we take several
131
127
// shortcuts to improve the runtime so that the sort may be done in
132
128
// time linear to the cardinality of the span Vec. Practically speaking
133
129
// the runtime is even better since we only scan from `self.index` to
134
130
// the first element of the Vec with a `span.start` after this span.
135
- let intersect_span = Span {
136
- start : intersect,
137
- ..first_partitioned_span
138
- } ;
139
-
140
131
let num_spans_to_resort = self . spans [ i..]
141
132
. iter ( )
142
- . take_while ( |& & span| span <= intersect_span )
133
+ . take_while ( |& & span| span. start <= intersect )
143
134
. count ( ) ;
144
135
145
136
// Rotate the subsliced spans so that they come after the spans that
146
137
// have smaller `span.start`s.
147
138
if num_spans_to_resort != 0 {
148
139
let first_sorted_span = i + num_spans_to_resort;
149
- self . spans [ self . index ..first_sorted_span] . rotate_left ( num_partitioned_spans ) ;
140
+ self . spans [ self . index ..first_sorted_span] . sort_unstable ( ) ;
150
141
}
151
142
}
152
143
}
0 commit comments