@@ -142,6 +142,7 @@ impl TraitImpls {
142
142
143
143
let crate_def_map = db. crate_def_map ( krate) ;
144
144
impls. collect_def_map ( db, & crate_def_map) ;
145
+ impls. shrink_to_fit ( ) ;
145
146
146
147
Arc :: new ( impls)
147
148
}
@@ -155,10 +156,32 @@ impl TraitImpls {
155
156
156
157
let block_def_map = db. block_def_map ( block) ?;
157
158
impls. collect_def_map ( db, & block_def_map) ;
159
+ impls. shrink_to_fit ( ) ;
158
160
159
161
Some ( Arc :: new ( impls) )
160
162
}
161
163
164
+ pub ( crate ) fn trait_impls_in_deps_query ( db : & dyn HirDatabase , krate : CrateId ) -> Arc < Self > {
165
+ let _p = profile:: span ( "trait_impls_in_deps_query" ) ;
166
+ let crate_graph = db. crate_graph ( ) ;
167
+ let mut res = Self { map : FxHashMap :: default ( ) } ;
168
+
169
+ for krate in crate_graph. transitive_deps ( krate) {
170
+ res. merge ( & db. trait_impls_in_crate ( krate) ) ;
171
+ }
172
+ res. shrink_to_fit ( ) ;
173
+
174
+ Arc :: new ( res)
175
+ }
176
+
177
+ fn shrink_to_fit ( & mut self ) {
178
+ self . map . shrink_to_fit ( ) ;
179
+ self . map . values_mut ( ) . for_each ( |map| {
180
+ map. shrink_to_fit ( ) ;
181
+ map. values_mut ( ) . for_each ( Vec :: shrink_to_fit) ;
182
+ } ) ;
183
+ }
184
+
162
185
fn collect_def_map ( & mut self , db : & dyn HirDatabase , def_map : & DefMap ) {
163
186
for ( _module_id, module_data) in def_map. modules ( ) {
164
187
for impl_id in module_data. scope . impls ( ) {
@@ -187,18 +210,6 @@ impl TraitImpls {
187
210
}
188
211
}
189
212
190
- pub ( crate ) fn trait_impls_in_deps_query ( db : & dyn HirDatabase , krate : CrateId ) -> Arc < Self > {
191
- let _p = profile:: span ( "trait_impls_in_deps_query" ) ;
192
- let crate_graph = db. crate_graph ( ) ;
193
- let mut res = Self { map : FxHashMap :: default ( ) } ;
194
-
195
- for krate in crate_graph. transitive_deps ( krate) {
196
- res. merge ( & db. trait_impls_in_crate ( krate) ) ;
197
- }
198
-
199
- Arc :: new ( res)
200
- }
201
-
202
213
fn merge ( & mut self , other : & Self ) {
203
214
for ( trait_, other_map) in & other. map {
204
215
let map = self . map . entry ( * trait_) . or_default ( ) ;
@@ -264,6 +275,7 @@ impl InherentImpls {
264
275
265
276
let crate_def_map = db. crate_def_map ( krate) ;
266
277
impls. collect_def_map ( db, & crate_def_map) ;
278
+ impls. shrink_to_fit ( ) ;
267
279
268
280
return Arc :: new ( impls) ;
269
281
}
@@ -275,11 +287,17 @@ impl InherentImpls {
275
287
let mut impls = Self { map : FxHashMap :: default ( ) } ;
276
288
if let Some ( block_def_map) = db. block_def_map ( block) {
277
289
impls. collect_def_map ( db, & block_def_map) ;
290
+ impls. shrink_to_fit ( ) ;
278
291
return Some ( Arc :: new ( impls) ) ;
279
292
}
280
293
return None ;
281
294
}
282
295
296
+ fn shrink_to_fit ( & mut self ) {
297
+ self . map . values_mut ( ) . for_each ( Vec :: shrink_to_fit) ;
298
+ self . map . shrink_to_fit ( ) ;
299
+ }
300
+
283
301
fn collect_def_map ( & mut self , db : & dyn HirDatabase , def_map : & DefMap ) {
284
302
for ( _module_id, module_data) in def_map. modules ( ) {
285
303
for impl_id in module_data. scope . impls ( ) {
0 commit comments