Skip to content

Commit f3e1a01

Browse files
committed
Update associated_item_def_ids
1 parent d35181a commit f3e1a01

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
@@ -264,7 +264,7 @@ rustc_queries! {
264264

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

269269
/// Maps from a trait item to the trait item "descriptor"
270270
query associated_item(_: DefId) -> ty::AssociatedItem {}

src/librustc/ty/mod.rs

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

31073107
pub struct AssociatedItemsIterator<'a, 'gcx: 'tcx, 'tcx: 'a> {
31083108
tcx: TyCtxt<'a, 'gcx, 'tcx>,
3109-
def_ids: Lrc<Vec<DefId>>,
3109+
def_ids: &'gcx [DefId],
31103110
next_index: usize,
31113111
}
31123112

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

31843184
fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
31853185
def_id: DefId)
3186-
-> Lrc<Vec<DefId>> {
3186+
-> &'tcx [DefId] {
31873187
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
31883188
let item = tcx.hir().expect_item_by_hir_id(id);
3189-
let vec: Vec<_> = match item.node {
3189+
match item.node {
31903190
hir::ItemKind::Trait(.., ref trait_item_refs) => {
3191-
trait_item_refs.iter()
3192-
.map(|trait_item_ref| trait_item_ref.id)
3193-
.map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
3194-
.collect()
3191+
tcx.arena.alloc_from_iter(
3192+
trait_item_refs.iter()
3193+
.map(|trait_item_ref| trait_item_ref.id)
3194+
.map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
3195+
)
31953196
}
31963197
hir::ItemKind::Impl(.., ref impl_item_refs) => {
3197-
impl_item_refs.iter()
3198-
.map(|impl_item_ref| impl_item_ref.id)
3199-
.map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
3200-
.collect()
3198+
tcx.arena.alloc_from_iter(
3199+
impl_item_refs.iter()
3200+
.map(|impl_item_ref| impl_item_ref.id)
3201+
.map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
3202+
)
32013203
}
3202-
hir::ItemKind::TraitAlias(..) => vec![],
3204+
hir::ItemKind::TraitAlias(..) => &[],
32033205
_ => span_bug!(item.span, "associated_item_def_ids: not impl or trait")
3204-
};
3205-
Lrc::new(vec)
3206+
}
32063207
}
32073208

32083209
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
@@ -21,6 +21,7 @@ use rustc::hir::map::definitions::DefPathTable;
2121
use rustc::util::nodemap::DefIdMap;
2222
use rustc_data_structures::svh::Svh;
2323

24+
use smallvec::SmallVec;
2425
use std::any::Any;
2526
use rustc_data_structures::sync::Lrc;
2627
use std::sync::Arc;
@@ -108,10 +109,10 @@ provide! { <'tcx> tcx, def_id, other, cdata,
108109
}
109110
variances_of => { tcx.arena.alloc_from_iter(cdata.get_item_variances(def_id.index)) }
110111
associated_item_def_ids => {
111-
let mut result = vec![];
112+
let mut result = SmallVec::<[_; 8]>::new();
112113
cdata.each_child_of_item(def_id.index,
113114
|child| result.push(child.res.def_id()), tcx.sess);
114-
Lrc::new(result)
115+
tcx.arena.alloc_slice(&result)
115116
}
116117
associated_item => { cdata.get_associated_item(def_id.index) }
117118
impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) }

0 commit comments

Comments
 (0)