@@ -149,7 +149,8 @@ impl Compiler {
149
149
self . compiled . start = dotstar_patch. entry ;
150
150
}
151
151
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 ( ) ) ;
153
154
if self . compiled . needs_dotstar ( ) {
154
155
self . fill ( dotstar_patch. hole , patch. entry ) ;
155
156
} else {
@@ -185,15 +186,15 @@ impl Compiler {
185
186
self . fill_to_next ( prev_hole) ;
186
187
let split = self . push_split_hole ( ) ;
187
188
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 ( ) ) ;
189
190
self . fill_to_next ( hole) ;
190
191
self . compiled . matches . push ( self . insts . len ( ) ) ;
191
192
self . push_compiled ( Inst :: Match ( i) ) ;
192
193
prev_hole = self . fill_split ( split, Some ( entry) , None ) ;
193
194
}
194
195
let i = exprs. len ( ) - 1 ;
195
196
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 ( ) ) ;
197
198
self . fill ( prev_hole, entry) ;
198
199
self . fill_to_next ( hole) ;
199
200
self . compiled . matches . push ( self . insts . len ( ) ) ;
@@ -410,11 +411,11 @@ impl Compiler {
410
411
} else {
411
412
let entry = self . insts . len ( ) ;
412
413
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 ( ) ) ;
414
415
self . fill ( hole, patch. entry ) ;
415
416
self . fill_to_next ( patch. hole ) ;
416
417
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 } ) )
418
419
}
419
420
}
420
421
@@ -448,7 +449,7 @@ impl Compiler {
448
449
self . c_class ( & [ hir:: ClassUnicodeRange :: new ( c, c) ] )
449
450
}
450
451
} else {
451
- let hole = self . push_hole ( InstHole :: Char { c : c } ) ;
452
+ let hole = self . push_hole ( InstHole :: Char { c } ) ;
452
453
Ok ( Some ( Patch { hole, entry : self . insts . len ( ) - 1 } ) )
453
454
}
454
455
}
@@ -458,7 +459,7 @@ impl Compiler {
458
459
459
460
assert ! ( !ranges. is_empty( ) ) ;
460
461
if self . compiled . uses_bytes ( ) {
461
- Ok ( Some ( CompileClass { c : self , ranges : ranges } . compile ( ) ?) )
462
+ Ok ( Some ( CompileClass { c : self , ranges } . compile ( ) ?) )
462
463
} else {
463
464
let ranges: Vec < ( char , char ) > =
464
465
ranges. iter ( ) . map ( |r| ( r. start ( ) , r. end ( ) ) ) . collect ( ) ;
@@ -467,9 +468,9 @@ impl Compiler {
467
468
} else {
468
469
self . extra_inst_bytes +=
469
470
ranges. len ( ) * ( size_of :: < char > ( ) * 2 ) ;
470
- self . push_hole ( InstHole :: Ranges { ranges : ranges } )
471
+ self . push_hole ( InstHole :: Ranges { ranges } )
471
472
} ;
472
- Ok ( Some ( Patch { hole : hole , entry : self . insts . len ( ) - 1 } ) )
473
+ Ok ( Some ( Patch { hole, entry : self . insts . len ( ) - 1 } ) )
473
474
}
474
475
}
475
476
@@ -508,8 +509,8 @@ impl Compiler {
508
509
}
509
510
510
511
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 } ) )
513
514
}
514
515
515
516
fn c_concat < ' a , I > ( & mut self , exprs : I ) -> ResultOrEmpty
@@ -533,7 +534,7 @@ impl Compiler {
533
534
hole = p. hole ;
534
535
}
535
536
}
536
- Ok ( Some ( Patch { hole : hole , entry : entry } ) )
537
+ Ok ( Some ( Patch { hole, entry } ) )
537
538
}
538
539
539
540
fn c_alternate ( & mut self , exprs : & [ Hir ] ) -> ResultOrEmpty {
@@ -676,7 +677,7 @@ impl Compiler {
676
677
// None).
677
678
let patch_concat = self
678
679
. c_concat ( iter:: repeat ( expr) . take ( min) ) ?
679
- . unwrap_or ( self . next_inst ( ) ) ;
680
+ . unwrap_or_else ( || self . next_inst ( ) ) ;
680
681
if let Some ( patch_rep) = self . c_repeat_zero_or_more ( expr, greedy) ? {
681
682
self . fill ( patch_concat. hole , patch_rep. entry ) ;
682
683
Ok ( Some ( Patch { hole : patch_rep. hole , entry : patch_concat. entry } ) )
@@ -700,7 +701,7 @@ impl Compiler {
700
701
}
701
702
// Same reasoning as in c_repeat_range_min_or_more (we know that min <
702
703
// 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 ( ) ) ;
704
705
let initial_entry = patch_concat. entry ;
705
706
// It is much simpler to compile, e.g., `a{2,5}` as:
706
707
//
@@ -879,14 +880,14 @@ impl MaybeInst {
879
880
}
880
881
MaybeInst :: Split1 ( goto1) => {
881
882
MaybeInst :: Compiled ( Inst :: Split ( InstSplit {
882
- goto1 : goto1 ,
883
+ goto1,
883
884
goto2 : goto,
884
885
} ) )
885
886
}
886
887
MaybeInst :: Split2 ( goto2) => {
887
888
MaybeInst :: Compiled ( Inst :: Split ( InstSplit {
888
889
goto1 : goto,
889
- goto2 : goto2 ,
890
+ goto2,
890
891
} ) )
891
892
}
892
893
_ => unreachable ! (
@@ -900,9 +901,7 @@ impl MaybeInst {
900
901
901
902
fn fill_split ( & mut self , goto1 : InstPtr , goto2 : InstPtr ) {
902
903
let filled = match * self {
903
- MaybeInst :: Split => {
904
- Inst :: Split ( InstSplit { goto1 : goto1, goto2 : goto2 } )
905
- }
904
+ MaybeInst :: Split => Inst :: Split ( InstSplit { goto1, goto2 } ) ,
906
905
_ => unreachable ! (
907
906
"must be called on Split instruction, \
908
907
instead it was called on: {:?}",
@@ -960,19 +959,17 @@ enum InstHole {
960
959
impl InstHole {
961
960
fn fill ( & self , goto : InstPtr ) -> Inst {
962
961
match * self {
963
- InstHole :: Save { slot } => {
964
- Inst :: Save ( InstSave { goto : goto, slot : slot } )
965
- }
962
+ InstHole :: Save { slot } => Inst :: Save ( InstSave { goto, slot } ) ,
966
963
InstHole :: EmptyLook { look } => {
967
- Inst :: EmptyLook ( InstEmptyLook { goto : goto , look : look } )
964
+ Inst :: EmptyLook ( InstEmptyLook { goto, look } )
968
965
}
969
- InstHole :: Char { c } => Inst :: Char ( InstChar { goto : goto , c : c } ) ,
966
+ InstHole :: Char { c } => Inst :: Char ( InstChar { goto, c } ) ,
970
967
InstHole :: Ranges { ref ranges } => Inst :: Ranges ( InstRanges {
971
- goto : goto ,
968
+ goto,
972
969
ranges : ranges. clone ( ) . into_boxed_slice ( ) ,
973
970
} ) ,
974
971
InstHole :: Bytes { start, end } => {
975
- Inst :: Bytes ( InstBytes { goto : goto , start : start , end : end } )
972
+ Inst :: Bytes ( InstBytes { goto, start, end } )
976
973
}
977
974
}
978
975
}
@@ -1042,7 +1039,7 @@ impl<'a, 'b> CompileClass<'a, 'b> {
1042
1039
let mut last_hole = Hole :: None ;
1043
1040
for byte_range in seq {
1044
1041
let key = SuffixCacheKey {
1045
- from_inst : from_inst ,
1042
+ from_inst,
1046
1043
start : byte_range. start ,
1047
1044
end : byte_range. end ,
1048
1045
} ;
@@ -1132,7 +1129,7 @@ impl SuffixCache {
1132
1129
}
1133
1130
}
1134
1131
* pos = self . dense . len ( ) ;
1135
- self . dense . push ( SuffixCacheEntry { key : key , pc : pc } ) ;
1132
+ self . dense . push ( SuffixCacheEntry { key, pc } ) ;
1136
1133
None
1137
1134
}
1138
1135
@@ -1143,8 +1140,8 @@ impl SuffixCache {
1143
1140
fn hash ( & self , suffix : & SuffixCacheKey ) -> usize {
1144
1141
// Basic FNV-1a hash as described:
1145
1142
// 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 ;
1148
1145
h = ( h ^ ( suffix. from_inst as u64 ) ) . wrapping_mul ( FNV_PRIME ) ;
1149
1146
h = ( h ^ ( suffix. start as u64 ) ) . wrapping_mul ( FNV_PRIME ) ;
1150
1147
h = ( h ^ ( suffix. end as u64 ) ) . wrapping_mul ( FNV_PRIME ) ;
0 commit comments