Skip to content

Commit 8da50c9

Browse files
jonas-schievinkJonas Schievink
authored andcommitted
Change ChildBySource to allow reusing DynMap
1 parent c45ac6e commit 8da50c9

File tree

2 files changed

+18
-32
lines changed

2 files changed

+18
-32
lines changed

crates/hir_def/src/child_by_source.rs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ use crate::{
1717
};
1818

1919
pub trait ChildBySource {
20-
fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap;
21-
}
22-
23-
impl ChildBySource for TraitId {
2420
fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
2521
let mut res = DynMap::default();
22+
self.child_by_source_to(db, &mut res);
23+
res
24+
}
25+
fn child_by_source_to(&self, db: &dyn DefDatabase, map: &mut DynMap);
26+
}
2627

28+
impl ChildBySource for TraitId {
29+
fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap) {
2730
let data = db.trait_data(*self);
2831
for (_name, item) in data.items.iter() {
2932
match *item {
@@ -41,15 +44,11 @@ impl ChildBySource for TraitId {
4144
}
4245
}
4346
}
44-
45-
res
4647
}
4748
}
4849

4950
impl ChildBySource for ImplId {
50-
fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
51-
let mut res = DynMap::default();
52-
51+
fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap) {
5352
let data = db.impl_data(*self);
5453
for &item in data.items.iter() {
5554
match item {
@@ -67,25 +66,21 @@ impl ChildBySource for ImplId {
6766
}
6867
}
6968
}
70-
71-
res
7269
}
7370
}
7471

7572
impl ChildBySource for ModuleId {
76-
fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
73+
fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap) {
7774
let def_map = self.def_map(db);
7875
let module_data = &def_map[self.local_id];
79-
module_data.scope.child_by_source(db)
76+
module_data.scope.child_by_source_to(db, res);
8077
}
8178
}
8279

8380
impl ChildBySource for ItemScope {
84-
fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
85-
let mut res = DynMap::default();
86-
self.declarations().for_each(|item| add_module_def(db, &mut res, item));
87-
self.impls().for_each(|imp| add_impl(db, &mut res, imp));
88-
return res;
81+
fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap) {
82+
self.declarations().for_each(|item| add_module_def(db, res, item));
83+
self.impls().for_each(|imp| add_impl(db, res, imp));
8984

9085
fn add_module_def(db: &dyn DefDatabase, map: &mut DynMap, item: ModuleDefId) {
9186
match item {
@@ -134,9 +129,7 @@ impl ChildBySource for ItemScope {
134129
}
135130

136131
impl ChildBySource for VariantId {
137-
fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
138-
let mut res = DynMap::default();
139-
132+
fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap) {
140133
let arena_map = self.child_source(db);
141134
let arena_map = arena_map.as_ref();
142135
for (local_id, source) in arena_map.value.iter() {
@@ -150,28 +143,23 @@ impl ChildBySource for VariantId {
150143
}
151144
}
152145
}
153-
res
154146
}
155147
}
156148

157149
impl ChildBySource for EnumId {
158-
fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
159-
let mut res = DynMap::default();
160-
150+
fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap) {
161151
let arena_map = self.child_source(db);
162152
let arena_map = arena_map.as_ref();
163153
for (local_id, source) in arena_map.value.iter() {
164154
let id = EnumVariantId { parent: *self, local_id };
165155
res[keys::VARIANT].insert(arena_map.with_value(source.clone()), id)
166156
}
167-
168-
res
169157
}
170158
}
171159

172160
impl ChildBySource for DefWithBodyId {
173-
fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
161+
fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap) {
174162
let body = db.body(*self);
175-
body.item_scope.child_by_source(db)
163+
body.item_scope.child_by_source_to(db, res);
176164
}
177165
}

crates/hir_def/src/generics.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,7 @@ impl HasChildSource<LocalConstParamId> for GenericDefId {
421421
}
422422

423423
impl ChildBySource for GenericDefId {
424-
fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
425-
let mut res = DynMap::default();
424+
fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap) {
426425
let (_, sm) = GenericParams::new(db, *self);
427426

428427
let sm = sm.as_ref();
@@ -440,6 +439,5 @@ impl ChildBySource for GenericDefId {
440439
let id = ConstParamId { parent: *self, local_id };
441440
res[keys::CONST_PARAM].insert(sm.with_value(src.clone()), id);
442441
}
443-
res
444442
}
445443
}

0 commit comments

Comments
 (0)