@@ -266,7 +266,7 @@ where
266266 }
267267
268268 #[ cfg( test) ]
269- pub ( crate ) fn from_edges < B : Copy + Into < Byte > > (
269+ pub ( crate ) fn from_edges < B : Clone + Into < Byte > > (
270270 start : u32 ,
271271 accept : u32 ,
272272 edges : & [ ( u32 , B , u32 ) ] ,
@@ -275,8 +275,8 @@ where
275275 let accept = State ( accept) ;
276276 let mut transitions: Map < State , Vec < ( Byte , State ) > > = Map :: default ( ) ;
277277
278- for ( src, edge, dst) in edges. iter ( ) . copied ( ) {
279- transitions. entry ( State ( src) ) . or_default ( ) . push ( ( edge. into ( ) , State ( dst) ) ) ;
278+ for & ( src, ref edge, dst) in edges. iter ( ) {
279+ transitions. entry ( State ( src) ) . or_default ( ) . push ( ( edge. clone ( ) . into ( ) , State ( dst) ) ) ;
280280 }
281281
282282 let transitions = transitions
@@ -401,12 +401,24 @@ mod edge_set {
401401 mut join : impl FnMut ( Option < S > , Option < S > ) -> S ,
402402 ) -> EdgeSet < S >
403403 where
404- S : Copy ,
404+ S : Copy + Eq ,
405405 {
406+ let mut runs: SmallVec < [ ( Byte , S ) ; 1 ] > = SmallVec :: new ( ) ;
406407 let xs = self . runs . iter ( ) . copied ( ) ;
407408 let ys = other. runs . iter ( ) . copied ( ) ;
408- // FIXME(@joshlf): Merge contiguous runs with common destination.
409- EdgeSet { runs : union ( xs, ys) . map ( |( range, ( x, y) ) | ( range, join ( x, y) ) ) . collect ( ) }
409+ for ( range, ( x, y) ) in union ( xs, ys) {
410+ let state = join ( x, y) ;
411+ match runs. last_mut ( ) {
412+ // Merge contiguous runs with a common destination.
413+ Some ( & mut ( ref mut last_range, ref mut last_state) )
414+ if last_range. end == range. start && * last_state == state =>
415+ {
416+ last_range. end = range. end
417+ }
418+ _ => runs. push ( ( range, state) ) ,
419+ }
420+ }
421+ EdgeSet { runs }
410422 }
411423 }
412424}
0 commit comments