Skip to content

Commit e153103

Browse files
committed
rustc/ty: improve allocations
1 parent 029e261 commit e153103

File tree

4 files changed

+32
-38
lines changed

4 files changed

+32
-38
lines changed

src/librustc/ty/inhabitedness/def_id_forest.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ impl<'a, 'gcx, 'tcx> DefIdForest {
8787
}
8888
ret.root_ids.extend(old_ret.drain());
8989

90-
for id in next_forest.root_ids {
91-
if ret.contains(tcx, id) {
92-
next_ret.push(id);
93-
}
94-
}
90+
next_ret.extend(next_forest.root_ids.into_iter().filter(|&id| ret.contains(tcx, id)));
9591

9692
mem::swap(&mut next_ret, &mut ret.root_ids);
9793
next_ret.drain();
@@ -107,11 +103,7 @@ impl<'a, 'gcx, 'tcx> DefIdForest {
107103
let mut ret = DefIdForest::empty();
108104
let mut next_ret = SmallVec::new();
109105
for next_forest in iter {
110-
for id in ret.root_ids.drain() {
111-
if !next_forest.contains(tcx, id) {
112-
next_ret.push(id);
113-
}
114-
}
106+
next_ret.extend(ret.root_ids.drain().filter(|&id| !next_forest.contains(tcx, id)));
115107

116108
for id in next_forest.root_ids {
117109
if !next_ret.contains(&id) {

src/librustc/ty/query/job.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ fn remove_cycle<'tcx>(
388388

389389
// Find the queries in the cycle which are
390390
// connected to queries outside the cycle
391-
let entry_points: Vec<Lrc<QueryJob<'tcx>>> = stack.iter().filter_map(|query| {
391+
let entry_points = stack.iter().filter_map(|query| {
392392
// Mark all the other queries in the cycle as already visited
393393
let mut visited = FxHashSet::from_iter(stack.iter().filter_map(|q| {
394394
if q.1.as_ptr() != query.1.as_ptr() {
@@ -403,12 +403,12 @@ fn remove_cycle<'tcx>(
403403
} else {
404404
None
405405
}
406-
}).collect();
406+
});
407407

408408
// Deterministically pick an entry point
409409
// FIXME: Sort this instead
410410
let mut hcx = tcx.create_stable_hashing_context();
411-
let entry_point = entry_points.iter().min_by_key(|q| {
411+
let entry_point = entry_points.min_by_key(|q| {
412412
let mut stable_hasher = StableHasher::<u64>::new();
413413
q.info.query.hash_stable(&mut hcx, &mut stable_hasher);
414414
stable_hasher.finish()

src/librustc/ty/query/on_disk_cache.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -254,23 +254,19 @@ impl<'sess> OnDiskCache<'sess> {
254254
})?;
255255

256256
// Encode diagnostics
257-
let diagnostics_index = {
258-
let mut diagnostics_index = EncodedDiagnosticsIndex::new();
259-
260-
for (dep_node_index, diagnostics) in self.current_diagnostics
261-
.borrow()
262-
.iter() {
263-
let pos = AbsoluteBytePos::new(encoder.position());
264-
// Let's make sure we get the expected type here:
265-
let diagnostics: &EncodedDiagnostics = diagnostics;
266-
let dep_node_index =
267-
SerializedDepNodeIndex::new(dep_node_index.index());
268-
encoder.encode_tagged(dep_node_index, diagnostics)?;
269-
diagnostics_index.push((dep_node_index, pos));
270-
}
271-
272-
diagnostics_index
273-
};
257+
let diagnostics_index: EncodedDiagnosticsIndex = self.current_diagnostics.borrow()
258+
.iter()
259+
.map(|(dep_node_index, diagnostics)|
260+
{
261+
let pos = AbsoluteBytePos::new(encoder.position());
262+
// Let's make sure we get the expected type here:
263+
let diagnostics: &EncodedDiagnostics = diagnostics;
264+
let dep_node_index = SerializedDepNodeIndex::new(dep_node_index.index());
265+
encoder.encode_tagged(dep_node_index, diagnostics)?;
266+
267+
Ok((dep_node_index, pos))
268+
})
269+
.collect::<Result<_, _>>()?;
274270

275271
let interpret_alloc_index = {
276272
let mut interpret_alloc_index = Vec::new();
@@ -282,6 +278,7 @@ impl<'sess> OnDiskCache<'sess> {
282278
// otherwise, abort
283279
break;
284280
}
281+
interpret_alloc_index.reserve(new_n);
285282
for idx in n..new_n {
286283
let id = encoder.interpret_allocs_inverse[idx];
287284
let pos = encoder.position() as u32;

src/librustc/ty/query/plumbing.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -709,14 +709,19 @@ macro_rules! define_queries_inner {
709709

710710
// We use try_lock here since we are only called from the
711711
// deadlock handler, and this shouldn't be locked
712-
$(for v in self.$name.try_lock().unwrap().active.values() {
713-
match *v {
714-
QueryResult::Started(ref job) => jobs.push(job.clone()),
715-
_ => (),
716-
}
717-
})*
718-
719-
return jobs;
712+
$(
713+
jobs.extend(
714+
self.$name.try_lock().unwrap().active.values().filter_map(|v|
715+
if let QueryResult::Started(ref job) = *v {
716+
Some(job.clone())
717+
} else {
718+
None
719+
}
720+
)
721+
);
722+
)*
723+
724+
jobs
720725
}
721726
}
722727

0 commit comments

Comments
 (0)