@@ -139,7 +139,8 @@ impl Compiler {
139139 self . compiled . start = dotstar_patch. entry ;
140140 }
141141 self . compiled . captures = vec ! [ None ] ;
142- let patch = self . c_capture ( 0 , expr) ?. unwrap_or ( self . next_inst ( ) ) ;
142+ let patch =
143+ self . c_capture ( 0 , expr) ?. unwrap_or_else ( || self . next_inst ( ) ) ;
143144 if self . compiled . needs_dotstar ( ) {
144145 self . fill ( dotstar_patch. hole , patch. entry ) ;
145146 } else {
@@ -175,15 +176,15 @@ impl Compiler {
175176 self . fill_to_next ( prev_hole) ;
176177 let split = self . push_split_hole ( ) ;
177178 let Patch { hole, entry } =
178- self . c_capture ( 0 , expr) ?. unwrap_or ( self . next_inst ( ) ) ;
179+ self . c_capture ( 0 , expr) ?. unwrap_or_else ( || self . next_inst ( ) ) ;
179180 self . fill_to_next ( hole) ;
180181 self . compiled . matches . push ( self . insts . len ( ) ) ;
181182 self . push_compiled ( Inst :: Match ( i) ) ;
182183 prev_hole = self . fill_split ( split, Some ( entry) , None ) ;
183184 }
184185 let i = exprs. len ( ) - 1 ;
185186 let Patch { hole, entry } =
186- self . c_capture ( 0 , & exprs[ i] ) ?. unwrap_or ( self . next_inst ( ) ) ;
187+ self . c_capture ( 0 , & exprs[ i] ) ?. unwrap_or_else ( || self . next_inst ( ) ) ;
187188 self . fill ( prev_hole, entry) ;
188189 self . fill_to_next ( hole) ;
189190 self . compiled . matches . push ( self . insts . len ( ) ) ;
@@ -387,11 +388,11 @@ impl Compiler {
387388 } else {
388389 let entry = self . insts . len ( ) ;
389390 let hole = self . push_hole ( InstHole :: Save { slot : first_slot } ) ;
390- let patch = self . c ( expr) ?. unwrap_or ( self . next_inst ( ) ) ;
391+ let patch = self . c ( expr) ?. unwrap_or_else ( || self . next_inst ( ) ) ;
391392 self . fill ( hole, patch. entry ) ;
392393 self . fill_to_next ( patch. hole ) ;
393394 let hole = self . push_hole ( InstHole :: Save { slot : first_slot + 1 } ) ;
394- Ok ( Some ( Patch { hole : hole , entry : entry } ) )
395+ Ok ( Some ( Patch { hole, entry } ) )
395396 }
396397 }
397398
@@ -425,7 +426,7 @@ impl Compiler {
425426 self . c_class ( & [ hir:: ClassUnicodeRange :: new ( c, c) ] )
426427 }
427428 } else {
428- let hole = self . push_hole ( InstHole :: Char { c : c } ) ;
429+ let hole = self . push_hole ( InstHole :: Char { c } ) ;
429430 Ok ( Some ( Patch { hole, entry : self . insts . len ( ) - 1 } ) )
430431 }
431432 }
@@ -435,7 +436,7 @@ impl Compiler {
435436
436437 assert ! ( !ranges. is_empty( ) ) ;
437438 if self . compiled . uses_bytes ( ) {
438- Ok ( Some ( CompileClass { c : self , ranges : ranges } . compile ( ) ?) )
439+ Ok ( Some ( CompileClass { c : self , ranges } . compile ( ) ?) )
439440 } else {
440441 let ranges: Vec < ( char , char ) > =
441442 ranges. iter ( ) . map ( |r| ( r. start ( ) , r. end ( ) ) ) . collect ( ) ;
@@ -444,9 +445,9 @@ impl Compiler {
444445 } else {
445446 self . extra_inst_bytes +=
446447 ranges. len ( ) * ( size_of :: < char > ( ) * 2 ) ;
447- self . push_hole ( InstHole :: Ranges { ranges : ranges } )
448+ self . push_hole ( InstHole :: Ranges { ranges } )
448449 } ;
449- Ok ( Some ( Patch { hole : hole , entry : self . insts . len ( ) - 1 } ) )
450+ Ok ( Some ( Patch { hole, entry : self . insts . len ( ) - 1 } ) )
450451 }
451452 }
452453
@@ -485,8 +486,8 @@ impl Compiler {
485486 }
486487
487488 fn c_empty_look ( & mut self , look : EmptyLook ) -> ResultOrEmpty {
488- let hole = self . push_hole ( InstHole :: EmptyLook { look : look } ) ;
489- Ok ( Some ( Patch { hole : hole , entry : self . insts . len ( ) - 1 } ) )
489+ let hole = self . push_hole ( InstHole :: EmptyLook { look } ) ;
490+ Ok ( Some ( Patch { hole, entry : self . insts . len ( ) - 1 } ) )
490491 }
491492
492493 fn c_concat < ' a , I > ( & mut self , exprs : I ) -> ResultOrEmpty
@@ -510,7 +511,7 @@ impl Compiler {
510511 hole = p. hole ;
511512 }
512513 }
513- Ok ( Some ( Patch { hole : hole , entry : entry } ) )
514+ Ok ( Some ( Patch { hole, entry } ) )
514515 }
515516
516517 fn c_alternate ( & mut self , exprs : & [ Hir ] ) -> ResultOrEmpty {
@@ -653,7 +654,7 @@ impl Compiler {
653654 // None).
654655 let patch_concat = self
655656 . c_concat ( iter:: repeat ( expr) . take ( min) ) ?
656- . unwrap_or ( self . next_inst ( ) ) ;
657+ . unwrap_or_else ( || self . next_inst ( ) ) ;
657658 if let Some ( patch_rep) = self . c_repeat_zero_or_more ( expr, greedy) ? {
658659 self . fill ( patch_concat. hole , patch_rep. entry ) ;
659660 Ok ( Some ( Patch { hole : patch_rep. hole , entry : patch_concat. entry } ) )
@@ -677,7 +678,7 @@ impl Compiler {
677678 }
678679 // Same reasoning as in c_repeat_range_min_or_more (we know that min <
679680 // max at this point).
680- let patch_concat = patch_concat. unwrap_or ( self . next_inst ( ) ) ;
681+ let patch_concat = patch_concat. unwrap_or_else ( || self . next_inst ( ) ) ;
681682 let initial_entry = patch_concat. entry ;
682683 // It is much simpler to compile, e.g., `a{2,5}` as:
683684 //
@@ -856,14 +857,14 @@ impl MaybeInst {
856857 }
857858 MaybeInst :: Split1 ( goto1) => {
858859 MaybeInst :: Compiled ( Inst :: Split ( InstSplit {
859- goto1 : goto1 ,
860+ goto1,
860861 goto2 : goto,
861862 } ) )
862863 }
863864 MaybeInst :: Split2 ( goto2) => {
864865 MaybeInst :: Compiled ( Inst :: Split ( InstSplit {
865866 goto1 : goto,
866- goto2 : goto2 ,
867+ goto2,
867868 } ) )
868869 }
869870 _ => unreachable ! (
@@ -877,9 +878,7 @@ impl MaybeInst {
877878
878879 fn fill_split ( & mut self , goto1 : InstPtr , goto2 : InstPtr ) {
879880 let filled = match * self {
880- MaybeInst :: Split => {
881- Inst :: Split ( InstSplit { goto1 : goto1, goto2 : goto2 } )
882- }
881+ MaybeInst :: Split => Inst :: Split ( InstSplit { goto1, goto2 } ) ,
883882 _ => unreachable ! (
884883 "must be called on Split instruction, \
885884 instead it was called on: {:?}",
@@ -937,19 +936,17 @@ enum InstHole {
937936impl InstHole {
938937 fn fill ( & self , goto : InstPtr ) -> Inst {
939938 match * self {
940- InstHole :: Save { slot } => {
941- Inst :: Save ( InstSave { goto : goto, slot : slot } )
942- }
939+ InstHole :: Save { slot } => Inst :: Save ( InstSave { goto, slot } ) ,
943940 InstHole :: EmptyLook { look } => {
944- Inst :: EmptyLook ( InstEmptyLook { goto : goto , look : look } )
941+ Inst :: EmptyLook ( InstEmptyLook { goto, look } )
945942 }
946- InstHole :: Char { c } => Inst :: Char ( InstChar { goto : goto , c : c } ) ,
943+ InstHole :: Char { c } => Inst :: Char ( InstChar { goto, c } ) ,
947944 InstHole :: Ranges { ref ranges } => Inst :: Ranges ( InstRanges {
948- goto : goto ,
945+ goto,
949946 ranges : ranges. clone ( ) . into_boxed_slice ( ) ,
950947 } ) ,
951948 InstHole :: Bytes { start, end } => {
952- Inst :: Bytes ( InstBytes { goto : goto , start : start , end : end } )
949+ Inst :: Bytes ( InstBytes { goto, start, end } )
953950 }
954951 }
955952 }
@@ -1019,7 +1016,7 @@ impl<'a, 'b> CompileClass<'a, 'b> {
10191016 let mut last_hole = Hole :: None ;
10201017 for byte_range in seq {
10211018 let key = SuffixCacheKey {
1022- from_inst : from_inst ,
1019+ from_inst,
10231020 start : byte_range. start ,
10241021 end : byte_range. end ,
10251022 } ;
@@ -1109,7 +1106,7 @@ impl SuffixCache {
11091106 }
11101107 }
11111108 * pos = self . dense . len ( ) ;
1112- self . dense . push ( SuffixCacheEntry { key : key , pc : pc } ) ;
1109+ self . dense . push ( SuffixCacheEntry { key, pc } ) ;
11131110 None
11141111 }
11151112
@@ -1120,8 +1117,8 @@ impl SuffixCache {
11201117 fn hash ( & self , suffix : & SuffixCacheKey ) -> usize {
11211118 // Basic FNV-1a hash as described:
11221119 // https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
1123- const FNV_PRIME : u64 = 1099511628211 ;
1124- let mut h = 14695981039346656037 ;
1120+ const FNV_PRIME : u64 = 1_099_511_628_211 ;
1121+ let mut h = 14_695_981_039_346_656_037 ;
11251122 h = ( h ^ ( suffix. from_inst as u64 ) ) . wrapping_mul ( FNV_PRIME ) ;
11261123 h = ( h ^ ( suffix. start as u64 ) ) . wrapping_mul ( FNV_PRIME ) ;
11271124 h = ( h ^ ( suffix. end as u64 ) ) . wrapping_mul ( FNV_PRIME ) ;
0 commit comments