@@ -149,7 +149,8 @@ impl Compiler {
149149 self . compiled . start = dotstar_patch. entry ;
150150 }
151151 self . compiled . captures = vec ! [ None ] ;
152- let patch = self . c_capture ( 0 , expr) ?. unwrap_or ( self . next_inst ( ) ) ;
152+ let patch =
153+ self . c_capture ( 0 , expr) ?. unwrap_or_else ( || self . next_inst ( ) ) ;
153154 if self . compiled . needs_dotstar ( ) {
154155 self . fill ( dotstar_patch. hole , patch. entry ) ;
155156 } else {
@@ -185,15 +186,15 @@ impl Compiler {
185186 self . fill_to_next ( prev_hole) ;
186187 let split = self . push_split_hole ( ) ;
187188 let Patch { hole, entry } =
188- self . c_capture ( 0 , expr) ?. unwrap_or ( self . next_inst ( ) ) ;
189+ self . c_capture ( 0 , expr) ?. unwrap_or_else ( || self . next_inst ( ) ) ;
189190 self . fill_to_next ( hole) ;
190191 self . compiled . matches . push ( self . insts . len ( ) ) ;
191192 self . push_compiled ( Inst :: Match ( i) ) ;
192193 prev_hole = self . fill_split ( split, Some ( entry) , None ) ;
193194 }
194195 let i = exprs. len ( ) - 1 ;
195196 let Patch { hole, entry } =
196- self . c_capture ( 0 , & exprs[ i] ) ?. unwrap_or ( self . next_inst ( ) ) ;
197+ self . c_capture ( 0 , & exprs[ i] ) ?. unwrap_or_else ( || self . next_inst ( ) ) ;
197198 self . fill ( prev_hole, entry) ;
198199 self . fill_to_next ( hole) ;
199200 self . compiled . matches . push ( self . insts . len ( ) ) ;
@@ -410,11 +411,11 @@ impl Compiler {
410411 } else {
411412 let entry = self . insts . len ( ) ;
412413 let hole = self . push_hole ( InstHole :: Save { slot : first_slot } ) ;
413- let patch = self . c ( expr) ?. unwrap_or ( self . next_inst ( ) ) ;
414+ let patch = self . c ( expr) ?. unwrap_or_else ( || self . next_inst ( ) ) ;
414415 self . fill ( hole, patch. entry ) ;
415416 self . fill_to_next ( patch. hole ) ;
416417 let hole = self . push_hole ( InstHole :: Save { slot : first_slot + 1 } ) ;
417- Ok ( Some ( Patch { hole : hole , entry : entry } ) )
418+ Ok ( Some ( Patch { hole, entry } ) )
418419 }
419420 }
420421
@@ -448,7 +449,7 @@ impl Compiler {
448449 self . c_class ( & [ hir:: ClassUnicodeRange :: new ( c, c) ] )
449450 }
450451 } else {
451- let hole = self . push_hole ( InstHole :: Char { c : c } ) ;
452+ let hole = self . push_hole ( InstHole :: Char { c } ) ;
452453 Ok ( Some ( Patch { hole, entry : self . insts . len ( ) - 1 } ) )
453454 }
454455 }
@@ -458,7 +459,7 @@ impl Compiler {
458459
459460 assert ! ( !ranges. is_empty( ) ) ;
460461 if self . compiled . uses_bytes ( ) {
461- Ok ( Some ( CompileClass { c : self , ranges : ranges } . compile ( ) ?) )
462+ Ok ( Some ( CompileClass { c : self , ranges } . compile ( ) ?) )
462463 } else {
463464 let ranges: Vec < ( char , char ) > =
464465 ranges. iter ( ) . map ( |r| ( r. start ( ) , r. end ( ) ) ) . collect ( ) ;
@@ -467,9 +468,9 @@ impl Compiler {
467468 } else {
468469 self . extra_inst_bytes +=
469470 ranges. len ( ) * ( size_of :: < char > ( ) * 2 ) ;
470- self . push_hole ( InstHole :: Ranges { ranges : ranges } )
471+ self . push_hole ( InstHole :: Ranges { ranges } )
471472 } ;
472- Ok ( Some ( Patch { hole : hole , entry : self . insts . len ( ) - 1 } ) )
473+ Ok ( Some ( Patch { hole, entry : self . insts . len ( ) - 1 } ) )
473474 }
474475 }
475476
@@ -508,8 +509,8 @@ impl Compiler {
508509 }
509510
510511 fn c_empty_look ( & mut self , look : EmptyLook ) -> ResultOrEmpty {
511- let hole = self . push_hole ( InstHole :: EmptyLook { look : look } ) ;
512- Ok ( Some ( Patch { hole : hole , entry : self . insts . len ( ) - 1 } ) )
512+ let hole = self . push_hole ( InstHole :: EmptyLook { look } ) ;
513+ Ok ( Some ( Patch { hole, entry : self . insts . len ( ) - 1 } ) )
513514 }
514515
515516 fn c_concat < ' a , I > ( & mut self , exprs : I ) -> ResultOrEmpty
@@ -533,7 +534,7 @@ impl Compiler {
533534 hole = p. hole ;
534535 }
535536 }
536- Ok ( Some ( Patch { hole : hole , entry : entry } ) )
537+ Ok ( Some ( Patch { hole, entry } ) )
537538 }
538539
539540 fn c_alternate ( & mut self , exprs : & [ Hir ] ) -> ResultOrEmpty {
@@ -676,7 +677,7 @@ impl Compiler {
676677 // None).
677678 let patch_concat = self
678679 . c_concat ( iter:: repeat ( expr) . take ( min) ) ?
679- . unwrap_or ( self . next_inst ( ) ) ;
680+ . unwrap_or_else ( || self . next_inst ( ) ) ;
680681 if let Some ( patch_rep) = self . c_repeat_zero_or_more ( expr, greedy) ? {
681682 self . fill ( patch_concat. hole , patch_rep. entry ) ;
682683 Ok ( Some ( Patch { hole : patch_rep. hole , entry : patch_concat. entry } ) )
@@ -700,7 +701,7 @@ impl Compiler {
700701 }
701702 // Same reasoning as in c_repeat_range_min_or_more (we know that min <
702703 // max at this point).
703- let patch_concat = patch_concat. unwrap_or ( self . next_inst ( ) ) ;
704+ let patch_concat = patch_concat. unwrap_or_else ( || self . next_inst ( ) ) ;
704705 let initial_entry = patch_concat. entry ;
705706 // It is much simpler to compile, e.g., `a{2,5}` as:
706707 //
@@ -879,14 +880,14 @@ impl MaybeInst {
879880 }
880881 MaybeInst :: Split1 ( goto1) => {
881882 MaybeInst :: Compiled ( Inst :: Split ( InstSplit {
882- goto1 : goto1 ,
883+ goto1,
883884 goto2 : goto,
884885 } ) )
885886 }
886887 MaybeInst :: Split2 ( goto2) => {
887888 MaybeInst :: Compiled ( Inst :: Split ( InstSplit {
888889 goto1 : goto,
889- goto2 : goto2 ,
890+ goto2,
890891 } ) )
891892 }
892893 _ => unreachable ! (
@@ -900,9 +901,7 @@ impl MaybeInst {
900901
901902 fn fill_split ( & mut self , goto1 : InstPtr , goto2 : InstPtr ) {
902903 let filled = match * self {
903- MaybeInst :: Split => {
904- Inst :: Split ( InstSplit { goto1 : goto1, goto2 : goto2 } )
905- }
904+ MaybeInst :: Split => Inst :: Split ( InstSplit { goto1, goto2 } ) ,
906905 _ => unreachable ! (
907906 "must be called on Split instruction, \
908907 instead it was called on: {:?}",
@@ -960,19 +959,17 @@ enum InstHole {
960959impl InstHole {
961960 fn fill ( & self , goto : InstPtr ) -> Inst {
962961 match * self {
963- InstHole :: Save { slot } => {
964- Inst :: Save ( InstSave { goto : goto, slot : slot } )
965- }
962+ InstHole :: Save { slot } => Inst :: Save ( InstSave { goto, slot } ) ,
966963 InstHole :: EmptyLook { look } => {
967- Inst :: EmptyLook ( InstEmptyLook { goto : goto , look : look } )
964+ Inst :: EmptyLook ( InstEmptyLook { goto, look } )
968965 }
969- InstHole :: Char { c } => Inst :: Char ( InstChar { goto : goto , c : c } ) ,
966+ InstHole :: Char { c } => Inst :: Char ( InstChar { goto, c } ) ,
970967 InstHole :: Ranges { ref ranges } => Inst :: Ranges ( InstRanges {
971- goto : goto ,
968+ goto,
972969 ranges : ranges. clone ( ) . into_boxed_slice ( ) ,
973970 } ) ,
974971 InstHole :: Bytes { start, end } => {
975- Inst :: Bytes ( InstBytes { goto : goto , start : start , end : end } )
972+ Inst :: Bytes ( InstBytes { goto, start, end } )
976973 }
977974 }
978975 }
@@ -1042,7 +1039,7 @@ impl<'a, 'b> CompileClass<'a, 'b> {
10421039 let mut last_hole = Hole :: None ;
10431040 for byte_range in seq {
10441041 let key = SuffixCacheKey {
1045- from_inst : from_inst ,
1042+ from_inst,
10461043 start : byte_range. start ,
10471044 end : byte_range. end ,
10481045 } ;
@@ -1132,7 +1129,7 @@ impl SuffixCache {
11321129 }
11331130 }
11341131 * pos = self . dense . len ( ) ;
1135- self . dense . push ( SuffixCacheEntry { key : key , pc : pc } ) ;
1132+ self . dense . push ( SuffixCacheEntry { key, pc } ) ;
11361133 None
11371134 }
11381135
@@ -1143,8 +1140,8 @@ impl SuffixCache {
11431140 fn hash ( & self , suffix : & SuffixCacheKey ) -> usize {
11441141 // Basic FNV-1a hash as described:
11451142 // https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
1146- const FNV_PRIME : u64 = 1099511628211 ;
1147- let mut h = 14695981039346656037 ;
1143+ const FNV_PRIME : u64 = 1_099_511_628_211 ;
1144+ let mut h = 14_695_981_039_346_656_037 ;
11481145 h = ( h ^ ( suffix. from_inst as u64 ) ) . wrapping_mul ( FNV_PRIME ) ;
11491146 h = ( h ^ ( suffix. start as u64 ) ) . wrapping_mul ( FNV_PRIME ) ;
11501147 h = ( h ^ ( suffix. end as u64 ) ) . wrapping_mul ( FNV_PRIME ) ;
0 commit comments