@@ -139,7 +139,7 @@ impl Compiler {
139
139
self . compiled . start = dotstar_patch. entry ;
140
140
}
141
141
self . compiled . captures = vec ! [ None ] ;
142
- let patch = self . c_capture ( 0 , expr) ?. unwrap_or ( self . next_inst ( ) ) ;
142
+ let patch = self . c_capture ( 0 , expr) ?. unwrap_or_else ( || self . next_inst ( ) ) ;
143
143
if self . compiled . needs_dotstar ( ) {
144
144
self . fill ( dotstar_patch. hole , patch. entry ) ;
145
145
} else {
@@ -175,15 +175,15 @@ impl Compiler {
175
175
self . fill_to_next ( prev_hole) ;
176
176
let split = self . push_split_hole ( ) ;
177
177
let Patch { hole, entry } =
178
- self . c_capture ( 0 , expr) ?. unwrap_or ( self . next_inst ( ) ) ;
178
+ self . c_capture ( 0 , expr) ?. unwrap_or_else ( || self . next_inst ( ) ) ;
179
179
self . fill_to_next ( hole) ;
180
180
self . compiled . matches . push ( self . insts . len ( ) ) ;
181
181
self . push_compiled ( Inst :: Match ( i) ) ;
182
182
prev_hole = self . fill_split ( split, Some ( entry) , None ) ;
183
183
}
184
184
let i = exprs. len ( ) - 1 ;
185
185
let Patch { hole, entry } =
186
- self . c_capture ( 0 , & exprs[ i] ) ?. unwrap_or ( self . next_inst ( ) ) ;
186
+ self . c_capture ( 0 , & exprs[ i] ) ?. unwrap_or_else ( || self . next_inst ( ) ) ;
187
187
self . fill ( prev_hole, entry) ;
188
188
self . fill_to_next ( hole) ;
189
189
self . compiled . matches . push ( self . insts . len ( ) ) ;
@@ -387,11 +387,11 @@ impl Compiler {
387
387
} else {
388
388
let entry = self . insts . len ( ) ;
389
389
let hole = self . push_hole ( InstHole :: Save { slot : first_slot } ) ;
390
- let patch = self . c ( expr) ?. unwrap_or ( self . next_inst ( ) ) ;
390
+ let patch = self . c ( expr) ?. unwrap_or_else ( || self . next_inst ( ) ) ;
391
391
self . fill ( hole, patch. entry ) ;
392
392
self . fill_to_next ( patch. hole ) ;
393
393
let hole = self . push_hole ( InstHole :: Save { slot : first_slot + 1 } ) ;
394
- Ok ( Some ( Patch { hole : hole , entry : entry } ) )
394
+ Ok ( Some ( Patch { hole, entry } ) )
395
395
}
396
396
}
397
397
@@ -425,7 +425,7 @@ impl Compiler {
425
425
self . c_class ( & [ hir:: ClassUnicodeRange :: new ( c, c) ] )
426
426
}
427
427
} else {
428
- let hole = self . push_hole ( InstHole :: Char { c : c } ) ;
428
+ let hole = self . push_hole ( InstHole :: Char { c } ) ;
429
429
Ok ( Some ( Patch { hole, entry : self . insts . len ( ) - 1 } ) )
430
430
}
431
431
}
@@ -435,7 +435,7 @@ impl Compiler {
435
435
436
436
assert ! ( !ranges. is_empty( ) ) ;
437
437
if self . compiled . uses_bytes ( ) {
438
- Ok ( Some ( CompileClass { c : self , ranges : ranges } . compile ( ) ?) )
438
+ Ok ( Some ( CompileClass { c : self , ranges } . compile ( ) ?) )
439
439
} else {
440
440
let ranges: Vec < ( char , char ) > =
441
441
ranges. iter ( ) . map ( |r| ( r. start ( ) , r. end ( ) ) ) . collect ( ) ;
@@ -444,9 +444,9 @@ impl Compiler {
444
444
} else {
445
445
self . extra_inst_bytes +=
446
446
ranges. len ( ) * ( size_of :: < char > ( ) * 2 ) ;
447
- self . push_hole ( InstHole :: Ranges { ranges : ranges } )
447
+ self . push_hole ( InstHole :: Ranges { ranges } )
448
448
} ;
449
- Ok ( Some ( Patch { hole : hole , entry : self . insts . len ( ) - 1 } ) )
449
+ Ok ( Some ( Patch { hole, entry : self . insts . len ( ) - 1 } ) )
450
450
}
451
451
}
452
452
@@ -485,8 +485,8 @@ impl Compiler {
485
485
}
486
486
487
487
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 } ) )
488
+ let hole = self . push_hole ( InstHole :: EmptyLook { look } ) ;
489
+ Ok ( Some ( Patch { hole, entry : self . insts . len ( ) - 1 } ) )
490
490
}
491
491
492
492
fn c_concat < ' a , I > ( & mut self , exprs : I ) -> ResultOrEmpty
@@ -510,7 +510,7 @@ impl Compiler {
510
510
hole = p. hole ;
511
511
}
512
512
}
513
- Ok ( Some ( Patch { hole : hole , entry : entry } ) )
513
+ Ok ( Some ( Patch { hole, entry } ) )
514
514
}
515
515
516
516
fn c_alternate ( & mut self , exprs : & [ Hir ] ) -> ResultOrEmpty {
@@ -653,7 +653,7 @@ impl Compiler {
653
653
// None).
654
654
let patch_concat = self
655
655
. c_concat ( iter:: repeat ( expr) . take ( min) ) ?
656
- . unwrap_or ( self . next_inst ( ) ) ;
656
+ . unwrap_or_else ( || self . next_inst ( ) ) ;
657
657
if let Some ( patch_rep) = self . c_repeat_zero_or_more ( expr, greedy) ? {
658
658
self . fill ( patch_concat. hole , patch_rep. entry ) ;
659
659
Ok ( Some ( Patch { hole : patch_rep. hole , entry : patch_concat. entry } ) )
@@ -677,7 +677,7 @@ impl Compiler {
677
677
}
678
678
// Same reasoning as in c_repeat_range_min_or_more (we know that min <
679
679
// max at this point).
680
- let patch_concat = patch_concat. unwrap_or ( self . next_inst ( ) ) ;
680
+ let patch_concat = patch_concat. unwrap_or_else ( || self . next_inst ( ) ) ;
681
681
let initial_entry = patch_concat. entry ;
682
682
// It is much simpler to compile, e.g., `a{2,5}` as:
683
683
//
@@ -856,14 +856,14 @@ impl MaybeInst {
856
856
}
857
857
MaybeInst :: Split1 ( goto1) => {
858
858
MaybeInst :: Compiled ( Inst :: Split ( InstSplit {
859
- goto1 : goto1 ,
859
+ goto1,
860
860
goto2 : goto,
861
861
} ) )
862
862
}
863
863
MaybeInst :: Split2 ( goto2) => {
864
864
MaybeInst :: Compiled ( Inst :: Split ( InstSplit {
865
865
goto1 : goto,
866
- goto2 : goto2 ,
866
+ goto2,
867
867
} ) )
868
868
}
869
869
_ => unreachable ! (
@@ -878,7 +878,7 @@ impl MaybeInst {
878
878
fn fill_split ( & mut self , goto1 : InstPtr , goto2 : InstPtr ) {
879
879
let filled = match * self {
880
880
MaybeInst :: Split => {
881
- Inst :: Split ( InstSplit { goto1 : goto1 , goto2 : goto2 } )
881
+ Inst :: Split ( InstSplit { goto1, goto2 } )
882
882
}
883
883
_ => unreachable ! (
884
884
"must be called on Split instruction, \
@@ -937,19 +937,17 @@ enum InstHole {
937
937
impl InstHole {
938
938
fn fill ( & self , goto : InstPtr ) -> Inst {
939
939
match * self {
940
- InstHole :: Save { slot } => {
941
- Inst :: Save ( InstSave { goto : goto, slot : slot } )
942
- }
940
+ InstHole :: Save { slot } => Inst :: Save ( InstSave { goto, slot } ) ,
943
941
InstHole :: EmptyLook { look } => {
944
- Inst :: EmptyLook ( InstEmptyLook { goto : goto , look : look } )
942
+ Inst :: EmptyLook ( InstEmptyLook { goto, look } )
945
943
}
946
- InstHole :: Char { c } => Inst :: Char ( InstChar { goto : goto , c : c } ) ,
944
+ InstHole :: Char { c } => Inst :: Char ( InstChar { goto, c } ) ,
947
945
InstHole :: Ranges { ref ranges } => Inst :: Ranges ( InstRanges {
948
- goto : goto ,
946
+ goto,
949
947
ranges : ranges. clone ( ) . into_boxed_slice ( ) ,
950
948
} ) ,
951
949
InstHole :: Bytes { start, end } => {
952
- Inst :: Bytes ( InstBytes { goto : goto , start : start , end : end } )
950
+ Inst :: Bytes ( InstBytes { goto, start, end } )
953
951
}
954
952
}
955
953
}
@@ -1019,7 +1017,7 @@ impl<'a, 'b> CompileClass<'a, 'b> {
1019
1017
let mut last_hole = Hole :: None ;
1020
1018
for byte_range in seq {
1021
1019
let key = SuffixCacheKey {
1022
- from_inst : from_inst ,
1020
+ from_inst,
1023
1021
start : byte_range. start ,
1024
1022
end : byte_range. end ,
1025
1023
} ;
@@ -1109,7 +1107,7 @@ impl SuffixCache {
1109
1107
}
1110
1108
}
1111
1109
* pos = self . dense . len ( ) ;
1112
- self . dense . push ( SuffixCacheEntry { key : key , pc : pc } ) ;
1110
+ self . dense . push ( SuffixCacheEntry { key, pc } ) ;
1113
1111
None
1114
1112
}
1115
1113
@@ -1120,8 +1118,8 @@ impl SuffixCache {
1120
1118
fn hash ( & self , suffix : & SuffixCacheKey ) -> usize {
1121
1119
// Basic FNV-1a hash as described:
1122
1120
// 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 ;
1121
+ const FNV_PRIME : u64 = 1_099_511_628_211 ;
1122
+ let mut h = 14_695_981_039_346_656_037 ;
1125
1123
h = ( h ^ ( suffix. from_inst as u64 ) ) . wrapping_mul ( FNV_PRIME ) ;
1126
1124
h = ( h ^ ( suffix. start as u64 ) ) . wrapping_mul ( FNV_PRIME ) ;
1127
1125
h = ( h ^ ( suffix. end as u64 ) ) . wrapping_mul ( FNV_PRIME ) ;
0 commit comments