@@ -180,8 +180,18 @@ impl LivenessResult {
180180 block,
181181 statement_index,
182182 } ;
183- let terminator_defs_uses = self . defs_uses ( mir, terminator_location, & data. terminator ) ;
184- terminator_defs_uses. apply ( & mut bits) ;
183+ let locals = mir. local_decls . len ( ) ;
184+ let mut visitor = DefsUsesVisitor {
185+ mode : self . mode ,
186+ defs_uses : DefsUses {
187+ defs : LocalSet :: new_empty ( locals) ,
188+ uses : LocalSet :: new_empty ( locals) ,
189+ } ,
190+ } ;
191+ // Visit the various parts of the basic block in reverse. If we go
192+ // forward, the logic in `add_def` and `add_use` would be wrong.
193+ data. terminator . apply ( terminator_location, & mut visitor) ;
194+ visitor. defs_uses . apply ( & mut bits) ;
185195 callback ( terminator_location, & bits) ;
186196
187197 // Compute liveness before each statement (in rev order) and invoke callback.
@@ -191,33 +201,14 @@ impl LivenessResult {
191201 block,
192202 statement_index,
193203 } ;
194- let statement_defs_uses = self . defs_uses ( mir, statement_location, statement) ;
195- statement_defs_uses. apply ( & mut bits) ;
204+ visitor. defs_uses . clear ( ) ;
205+ statement. apply ( statement_location, & mut visitor) ;
206+ visitor. defs_uses . apply ( & mut bits) ;
196207 callback ( statement_location, & bits) ;
197208 }
198209
199210 assert_eq ! ( bits, self . ins[ block] ) ;
200211 }
201-
202- fn defs_uses < ' tcx , V > ( & self , mir : & Mir < ' tcx > , location : Location , thing : & V ) -> DefsUses
203- where
204- V : MirVisitable < ' tcx > ,
205- {
206- let locals = mir. local_decls . len ( ) ;
207- let mut visitor = DefsUsesVisitor {
208- mode : self . mode ,
209- defs_uses : DefsUses {
210- defs : LocalSet :: new_empty ( locals) ,
211- uses : LocalSet :: new_empty ( locals) ,
212- } ,
213- } ;
214-
215- // Visit the various parts of the basic block in reverse. If we go
216- // forward, the logic in `add_def` and `add_use` would be wrong.
217- thing. apply ( location, & mut visitor) ;
218-
219- visitor. defs_uses
220- }
221212}
222213
223214#[ derive( Eq , PartialEq , Clone ) ]
@@ -307,6 +298,11 @@ struct DefsUses {
307298}
308299
309300impl DefsUses {
301+ fn clear ( & mut self ) {
302+ self . uses . clear ( ) ;
303+ self . defs . clear ( ) ;
304+ }
305+
310306 fn apply ( & self , bits : & mut LocalSet ) -> bool {
311307 bits. subtract ( & self . defs ) | bits. union ( & self . uses )
312308 }
0 commit comments