@@ -137,9 +137,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
137
137
statement_index : bbdata. statements . len ( ) ,
138
138
} ;
139
139
140
- if from_borrow
141
- && ( cannot_move_out || possible_borrower. only_borrowers ( & [ arg] [ ..] , cloned, loc) != Some ( true ) )
142
- {
140
+ if from_borrow && ( cannot_move_out || !possible_borrower. only_borrowers ( & [ arg] , cloned, loc) ) {
143
141
continue ;
144
142
}
145
143
@@ -171,7 +169,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
171
169
block : bb,
172
170
statement_index : mir. basic_blocks ( ) [ bb] . statements . len ( ) ,
173
171
} ;
174
- if cannot_move_out || possible_borrower. only_borrowers ( & [ arg, cloned] [ .. ] , local, loc) != Some ( true ) {
172
+ if cannot_move_out || ! possible_borrower. only_borrowers ( & [ arg, cloned] , local, loc) {
175
173
continue ;
176
174
}
177
175
local
@@ -564,29 +562,29 @@ fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) {
564
562
struct PossibleBorrower < ' a , ' tcx > {
565
563
map : FxHashMap < mir:: Local , HybridBitSet < mir:: Local > > ,
566
564
maybe_live : DataflowResultsCursor < ' a , ' tcx , MaybeStorageLive < ' a , ' tcx > > ,
565
+ // Caches to avoid allocation of `BitSet` on every query
567
566
bitset : ( BitSet < mir:: Local > , BitSet < mir:: Local > ) ,
568
567
}
569
568
570
569
impl PossibleBorrower < ' _ , ' _ > {
571
- fn only_borrowers < ' a > (
572
- & mut self ,
573
- borrowers : impl IntoIterator < Item = & ' a mir:: Local > ,
574
- borrowed : mir:: Local ,
575
- at : mir:: Location ,
576
- ) -> Option < bool > {
570
+ fn only_borrowers ( & mut self , borrowers : & [ mir:: Local ] , borrowed : mir:: Local , at : mir:: Location ) -> bool {
577
571
self . maybe_live . seek ( at) ;
578
572
579
573
self . bitset . 0 . clear ( ) ;
580
574
let maybe_live = & mut self . maybe_live ;
581
- for b in self . map . get ( & borrowed) ?. iter ( ) . filter ( move |b| maybe_live. contains ( * b) ) {
582
- self . bitset . 0 . insert ( b) ;
575
+ if let Some ( bitset) = self . map . get ( & borrowed) {
576
+ for b in bitset. iter ( ) . filter ( move |b| maybe_live. contains ( * b) ) {
577
+ self . bitset . 0 . insert ( b) ;
578
+ }
579
+ } else {
580
+ return false ;
583
581
}
584
582
585
583
self . bitset . 1 . clear ( ) ;
586
584
for b in borrowers {
587
585
self . bitset . 1 . insert ( * b) ;
588
586
}
589
587
590
- Some ( self . bitset . 0 == self . bitset . 1 )
588
+ self . bitset . 0 == self . bitset . 1
591
589
}
592
590
}
0 commit comments