@@ -266,7 +266,7 @@ where
266
266
}
267
267
268
268
#[ cfg( test) ]
269
- pub ( crate ) fn from_edges < B : Copy + Into < Byte > > (
269
+ pub ( crate ) fn from_edges < B : Clone + Into < Byte > > (
270
270
start : u32 ,
271
271
accept : u32 ,
272
272
edges : & [ ( u32 , B , u32 ) ] ,
@@ -275,8 +275,8 @@ where
275
275
let accept = State ( accept) ;
276
276
let mut transitions: Map < State , Vec < ( Byte , State ) > > = Map :: default ( ) ;
277
277
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) ) ) ;
280
280
}
281
281
282
282
let transitions = transitions
@@ -401,12 +401,24 @@ mod edge_set {
401
401
mut join : impl FnMut ( Option < S > , Option < S > ) -> S ,
402
402
) -> EdgeSet < S >
403
403
where
404
- S : Copy ,
404
+ S : Copy + Eq ,
405
405
{
406
+ let mut runs: SmallVec < [ ( Byte , S ) ; 1 ] > = SmallVec :: new ( ) ;
406
407
let xs = self . runs . iter ( ) . copied ( ) ;
407
408
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 }
410
422
}
411
423
}
412
424
}
0 commit comments