Skip to content

Commit

Permalink
Rollup merge of #129067 - cuviper:append, r=wesleywiser
Browse files Browse the repository at this point in the history
Use `append` instead of `extend(drain(..))`

The first commit adds `IndexVec::append` that forwards to `Vec::append`, and uses it in a couple places.

The second commit updates `indexmap` for its new `IndexMap::append`, and also uses that in a couple places.

These changes are similar to what [`clippy::extend_with_drain`](https://rust-lang.github.io/rust-clippy/master/index.html#/extend_with_drain) would suggest, just for other collection types.
  • Loading branch information
matthiaskrgr authored Aug 14, 2024
2 parents d14fa85 + ce67e68 commit c582c0c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1775,9 +1775,9 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"

[[package]]
name = "indexmap"
version = "2.2.6"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c"
dependencies = [
"equivalent",
"hashbrown",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bitflags = "2.4.1"
either = "1.0"
elsa = "=1.7.1"
ena = "0.14.3"
indexmap = { version = "2.0.0" }
indexmap = { version = "2.4.0" }
jobserver_crate = { version = "0.1.28", package = "jobserver" }
measureme = "11"
rustc-hash = "1.1.0"
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_index/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ impl<I: Idx, T> IndexVec<I, T> {
let min_new_len = elem.index() + 1;
self.raw.resize_with(min_new_len, fill_value);
}

#[inline]
pub fn append(&mut self, other: &mut Self) {
self.raw.append(&mut other.raw);
}
}

/// `IndexVec` is often used as a map, so it provides some map-like APIs.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ impl<'tcx> Inliner<'tcx> {

// Insert all of the (mapped) parts of the callee body into the caller.
caller_body.local_decls.extend(callee_body.drain_vars_and_temps());
caller_body.source_scopes.extend(&mut callee_body.source_scopes.drain(..));
caller_body.source_scopes.append(&mut callee_body.source_scopes);
if self
.tcx
.sess
Expand All @@ -740,7 +740,7 @@ impl<'tcx> Inliner<'tcx> {
// still getting consistent results from the mir-opt tests.
caller_body.var_debug_info.append(&mut callee_body.var_debug_info);
}
caller_body.basic_blocks_mut().extend(callee_body.basic_blocks_mut().drain(..));
caller_body.basic_blocks_mut().append(callee_body.basic_blocks_mut());

caller_body[callsite.block].terminator = Some(Terminator {
source_info: callsite.source_info,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_monomorphize/src/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ fn merge_codegen_units<'tcx>(
// Move the items from `cgu_src` to `cgu_dst`. Some of them may be
// duplicate inlined items, in which case the destination CGU is
// unaffected. Recalculate size estimates afterwards.
cgu_dst.items_mut().extend(cgu_src.items_mut().drain(..));
cgu_dst.items_mut().append(cgu_src.items_mut());
cgu_dst.compute_size_estimate();

// Record that `cgu_dst` now contains all the stuff that was in
Expand Down Expand Up @@ -410,7 +410,7 @@ fn merge_codegen_units<'tcx>(
// Move the items from `smallest` to `second_smallest`. Some of them
// may be duplicate inlined items, in which case the destination CGU is
// unaffected. Recalculate size estimates afterwards.
second_smallest.items_mut().extend(smallest.items_mut().drain(..));
second_smallest.items_mut().append(smallest.items_mut());
second_smallest.compute_size_estimate();

// Don't update `cgu_contents`, that's only for incremental builds.
Expand Down

0 comments on commit c582c0c

Please sign in to comment.