Skip to content

Commit 137f7e7

Browse files
committed
Update associated_item_def_ids
1 parent be2d6f2 commit 137f7e7

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

src/librustc/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ rustc_queries! {
275275

276276
Other {
277277
/// Maps from an impl/trait def-id to a list of the def-ids of its items
278-
query associated_item_def_ids(_: DefId) -> Lrc<Vec<DefId>> {
278+
query associated_item_def_ids(_: DefId) -> &'tcx [DefId] {
279279

280280
}
281281

src/librustc/ty/mod.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3071,7 +3071,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
30713071

30723072
pub struct AssociatedItemsIterator<'a, 'gcx: 'tcx, 'tcx: 'a> {
30733073
tcx: TyCtxt<'a, 'gcx, 'tcx>,
3074-
def_ids: Lrc<Vec<DefId>>,
3074+
def_ids: &'gcx [DefId],
30753075
next_index: usize,
30763076
}
30773077

@@ -3160,26 +3160,27 @@ fn adt_sized_constraint<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
31603160

31613161
fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
31623162
def_id: DefId)
3163-
-> Lrc<Vec<DefId>> {
3163+
-> &'tcx [DefId] {
31643164
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
31653165
let item = tcx.hir().expect_item_by_hir_id(id);
3166-
let vec: Vec<_> = match item.node {
3166+
match item.node {
31673167
hir::ItemKind::Trait(.., ref trait_item_refs) => {
3168-
trait_item_refs.iter()
3169-
.map(|trait_item_ref| trait_item_ref.id)
3170-
.map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
3171-
.collect()
3168+
tcx.arena.alloc_from_iter(
3169+
trait_item_refs.iter()
3170+
.map(|trait_item_ref| trait_item_ref.id)
3171+
.map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
3172+
)
31723173
}
31733174
hir::ItemKind::Impl(.., ref impl_item_refs) => {
3174-
impl_item_refs.iter()
3175-
.map(|impl_item_ref| impl_item_ref.id)
3176-
.map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
3177-
.collect()
3175+
tcx.arena.alloc_from_iter(
3176+
impl_item_refs.iter()
3177+
.map(|impl_item_ref| impl_item_ref.id)
3178+
.map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
3179+
)
31783180
}
3179-
hir::ItemKind::TraitAlias(..) => vec![],
3181+
hir::ItemKind::TraitAlias(..) => &[],
31803182
_ => span_bug!(item.span, "associated_item_def_ids: not impl or trait")
3181-
};
3182-
Lrc::new(vec)
3183+
}
31833184
}
31843185

31853186
fn def_span<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Span {

src/librustc_metadata/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ crate-type = ["dylib"]
1313
flate2 = "1.0"
1414
log = "0.4"
1515
memmap = "0.6"
16+
smallvec = { version = "0.6.7", features = ["union", "may_dangle"] }
1617
rustc = { path = "../librustc" }
1718
rustc_data_structures = { path = "../librustc_data_structures" }
1819
errors = { path = "../librustc_errors", package = "rustc_errors" }

src/librustc_metadata/cstore_impl.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc::hir::map::definitions::DefPathTable;
2020
use rustc::util::nodemap::DefIdMap;
2121
use rustc_data_structures::svh::Svh;
2222

23+
use smallvec::SmallVec;
2324
use std::any::Any;
2425
use rustc_data_structures::sync::Lrc;
2526
use std::sync::Arc;
@@ -107,10 +108,10 @@ provide! { <'tcx> tcx, def_id, other, cdata,
107108
}
108109
variances_of => { tcx.arena.alloc_from_iter(cdata.get_item_variances(def_id.index)) }
109110
associated_item_def_ids => {
110-
let mut result = vec![];
111+
let mut result = SmallVec::<[_; 8]>::new();
111112
cdata.each_child_of_item(def_id.index,
112113
|child| result.push(child.def.def_id()), tcx.sess);
113-
Lrc::new(result)
114+
tcx.arena.alloc_from_iter(result)
114115
}
115116
associated_item => { cdata.get_associated_item(def_id.index) }
116117
impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) }

0 commit comments

Comments
 (0)