diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2018-06-28 16:20:32 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2018-06-29 09:57:19 +1000 |
| commit | 08683f003cab472efc0481c349cb69dfb137c4c1 (patch) | |
| tree | 097f92369e0b42064adef34924d2485e59a022aa /src/librustc_data_structures | |
| parent | 99a9d6806d355b69fa66621df5208342de823aea (diff) | |
| download | rust-08683f003cab472efc0481c349cb69dfb137c4c1.tar.gz rust-08683f003cab472efc0481c349cb69dfb137c4c1.zip | |
Rename `IdxSet::clone_from`.
The current situation is something of a mess. - `IdxSetBuf` derefs to `IdxSet`. - `IdxSetBuf` implements `Clone`, and therefore has a provided `clone_from` method, which does allocation and so is expensive. - `IdxSet` has a `clone_from` method that is non-allocating and therefore cheap, but this method is not from the `Clone` trait. As a result, if you have an `IdxSetBuf` called `b`, if you call `b.clone_from(b2)` you'll get the expensive `IdxSetBuf` method, but if you call `(*b).clone_from(b2)` you'll get the cheap `IdxSetBuf` method. `liveness_of_locals()` does the former, presumably unintentionally, and therefore does lots of unnecessary allocations. Having a `clone_from` method that isn't from the `Clone` trait is a bad idea in general, so this patch renames it as `overwrite`. This avoids the unnecessary allocations in `liveness_of_locals()`, speeding up most NLL benchmarks, the best by 1.5%. It also means that calls of the form `(*b).clone_from(b2)` can be rewritten as `b.overwrite(b2)`.
Diffstat (limited to 'src/librustc_data_structures')
| -rw-r--r-- | src/librustc_data_structures/indexed_set.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/librustc_data_structures/indexed_set.rs b/src/librustc_data_structures/indexed_set.rs index c9495587c46..30b87c0390a 100644 --- a/src/librustc_data_structures/indexed_set.rs +++ b/src/librustc_data_structures/indexed_set.rs @@ -233,7 +233,9 @@ impl<T: Idx> IdxSet<T> { &mut self.bits } - pub fn clone_from(&mut self, other: &IdxSet<T>) { + /// Efficiently overwrite `self` with `other`. Panics if `self` and `other` + /// don't have the same length. + pub fn overwrite(&mut self, other: &IdxSet<T>) { self.words_mut().clone_from_slice(other.words()); } |
