Skip to content

Commit b31ab01

Browse files
authored
Unrolled build for #155778
Rollup merge of #155778 - kevinheavey:perf-mk-place-elem-avoid-vec-alloc, r=cjgillot,JohnTitor Avoid Vec allocation in TyCtxt::mk_place_elem `mk_place_elem` appends a single `PlaceElem` to an existing (interned) projection. The current implementation copies the projection into a fresh `Vec`, pushes the new element, and re-interns the slice, which allocates on every call. Feed the elements through `mk_place_elems_from_iter` so that `CollectAndApply`'s hand-unrolled stack fast path (up to 9 elements, in `rustc_type_ir::interner`) kicks in for the common case of short projections and the `Vec` allocation is skipped entirely. The behavior is identical for longer projections (the fast path falls back to a `Vec` internally).
2 parents ca9a134 + 5cd9d92 commit b31ab01

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

compiler/rustc_middle/src/ty/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,10 +2416,10 @@ impl<'tcx> TyCtxt<'tcx> {
24162416
/// to build a full `Place` it's just a convenient way to grab a projection and modify it in
24172417
/// flight.
24182418
pub fn mk_place_elem(self, place: Place<'tcx>, elem: PlaceElem<'tcx>) -> Place<'tcx> {
2419-
let mut projection = place.projection.to_vec();
2420-
projection.push(elem);
2421-
2422-
Place { local: place.local, projection: self.mk_place_elems(&projection) }
2419+
Place {
2420+
local: place.local,
2421+
projection: self.mk_place_elems_from_iter(place.projection.iter().chain([elem])),
2422+
}
24232423
}
24242424

24252425
pub fn mk_poly_existential_predicates(

0 commit comments

Comments
 (0)