Skip to content

Commit 1991a9b

Browse files
authored
Rollup merge of rust-lang#51869 - nnethercote:rm-clone_from, r=nikomatsakis
Avoid needless allocations in `liveness_of_locals`. We don't need to replace the heap-allocated bitset, we can just overwrite its contents. This speeds up most NLL benchmarks, the best by 1.5%. r? @nikomatsakis
2 parents 399b404 + 08683f0 commit 1991a9b

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

src/librustc_data_structures/indexed_set.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ impl<T: Idx> IdxSet<T> {
233233
&mut self.bits
234234
}
235235

236-
pub fn clone_from(&mut self, other: &IdxSet<T>) {
236+
/// Efficiently overwrite `self` with `other`. Panics if `self` and `other`
237+
/// don't have the same length.
238+
pub fn overwrite(&mut self, other: &IdxSet<T>) {
237239
self.words_mut().clone_from_slice(other.words());
238240
}
239241

src/librustc_mir/dataflow/at_location.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<BD> FlowsAtLocation for FlowAtLocation<BD>
139139
where BD: BitDenotation
140140
{
141141
fn reset_to_entry_of(&mut self, bb: BasicBlock) {
142-
(*self.curr_state).clone_from(self.base_results.sets().on_entry_set_for(bb.index()));
142+
self.curr_state.overwrite(self.base_results.sets().on_entry_set_for(bb.index()));
143143
}
144144

145145
fn reconstruct_statement_effect(&mut self, loc: Location) {

src/librustc_mir/dataflow/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl<'b, 'a: 'b, 'tcx: 'a, BD> PropagationContext<'b, 'a, 'tcx, BD> where BD: Bi
242242
{
243243
let sets = builder.flow_state.sets.for_block(bb_idx);
244244
debug_assert!(in_out.words().len() == sets.on_entry.words().len());
245-
in_out.clone_from(sets.on_entry);
245+
in_out.overwrite(sets.on_entry);
246246
in_out.union(sets.gen_set);
247247
in_out.subtract(sets.kill_set);
248248
}

src/librustc_mir/util/liveness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ pub fn liveness_of_locals<'tcx>(mir: &Mir<'tcx>, mode: LivenessMode) -> Liveness
141141
for &successor in mir.basic_blocks()[b].terminator().successors() {
142142
bits.union(&ins[successor]);
143143
}
144-
outs[b].clone_from(&bits);
144+
outs[b].overwrite(&bits);
145145

146146
// bits = use ∪ (bits - def)
147147
def_use[b].apply(&mut bits);
148148

149149
// update bits on entry and flag if they have changed
150150
if ins[b] != bits {
151-
ins[b].clone_from(&bits);
151+
ins[b].overwrite(&bits);
152152
changed = true;
153153
}
154154
}

0 commit comments

Comments
 (0)