mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
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).
This commit is contained in:
@@ -2416,10 +2416,10 @@ pub fn mk_place_index(self, place: Place<'tcx>, index: Local) -> Place<'tcx> {
|
||||
/// to build a full `Place` it's just a convenient way to grab a projection and modify it in
|
||||
/// flight.
|
||||
pub fn mk_place_elem(self, place: Place<'tcx>, elem: PlaceElem<'tcx>) -> Place<'tcx> {
|
||||
let mut projection = place.projection.to_vec();
|
||||
projection.push(elem);
|
||||
|
||||
Place { local: place.local, projection: self.mk_place_elems(&projection) }
|
||||
Place {
|
||||
local: place.local,
|
||||
projection: self.mk_place_elems_from_iter(place.projection.iter().chain([elem])),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mk_poly_existential_predicates(
|
||||
|
||||
Reference in New Issue
Block a user