Skip to content

Commit 22943ee

Browse files
committed
Remove unnecessary uses of ObligationForest::scratch.
They don't help performance at all, and just complicate things.
1 parent ea72650 commit 22943ee

File tree

1 file changed

+8
-12
lines changed
  • src/librustc_data_structures/obligation_forest

1 file changed

+8
-12
lines changed

src/librustc_data_structures/obligation_forest/mod.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,8 @@ pub struct ObligationForest<O: ForestObligation> {
151151
/// comments in `process_obligation` for details.
152152
active_cache: FxHashMap<O::Predicate, usize>,
153153

154-
/// A scratch vector reused in various operations, to avoid allocating new
155-
/// vectors.
156-
scratch: RefCell<Vec<usize>>,
154+
/// A vector reused in compress(), to avoid allocating new vectors.
155+
node_rewrites: RefCell<Vec<usize>>,
157156

158157
obligation_tree_id_generator: ObligationTreeIdGenerator,
159158

@@ -275,7 +274,7 @@ impl<O: ForestObligation> ObligationForest<O> {
275274
nodes: vec![],
276275
done_cache: Default::default(),
277276
active_cache: Default::default(),
278-
scratch: RefCell::new(vec![]),
277+
node_rewrites: RefCell::new(vec![]),
279278
obligation_tree_id_generator: (0..).map(ObligationTreeId),
280279
error_cache: Default::default(),
281280
}
@@ -472,8 +471,7 @@ impl<O: ForestObligation> ObligationForest<O> {
472471
fn process_cycles<P>(&self, processor: &mut P)
473472
where P: ObligationProcessor<Obligation=O>
474473
{
475-
let mut stack = self.scratch.replace(vec![]);
476-
debug_assert!(stack.is_empty());
474+
let mut stack = vec![];
477475

478476
debug!("process_cycles()");
479477

@@ -493,7 +491,6 @@ impl<O: ForestObligation> ObligationForest<O> {
493491
debug!("process_cycles: complete");
494492

495493
debug_assert!(stack.is_empty());
496-
self.scratch.replace(stack);
497494
}
498495

499496
fn find_cycles_from_node<P>(&self, stack: &mut Vec<usize>, processor: &mut P, index: usize)
@@ -533,7 +530,7 @@ impl<O: ForestObligation> ObligationForest<O> {
533530
/// Returns a vector of obligations for `p` and all of its
534531
/// ancestors, putting them into the error state in the process.
535532
fn error_at(&self, mut index: usize) -> Vec<O> {
536-
let mut error_stack = self.scratch.replace(vec![]);
533+
let mut error_stack: Vec<usize> = vec![];
537534
let mut trace = vec![];
538535

539536
loop {
@@ -562,7 +559,6 @@ impl<O: ForestObligation> ObligationForest<O> {
562559
error_stack.extend(node.dependents.iter());
563560
}
564561

565-
self.scratch.replace(error_stack);
566562
trace
567563
}
568564

@@ -617,7 +613,7 @@ impl<O: ForestObligation> ObligationForest<O> {
617613
#[inline(never)]
618614
fn compress(&mut self, do_completed: DoCompleted) -> Option<Vec<O>> {
619615
let nodes_len = self.nodes.len();
620-
let mut node_rewrites: Vec<_> = self.scratch.replace(vec![]);
616+
let mut node_rewrites: Vec<_> = self.node_rewrites.replace(vec![]);
621617
node_rewrites.extend(0..nodes_len);
622618
let mut dead_nodes = 0;
623619

@@ -667,7 +663,7 @@ impl<O: ForestObligation> ObligationForest<O> {
667663
// No compression needed.
668664
if dead_nodes == 0 {
669665
node_rewrites.truncate(0);
670-
self.scratch.replace(node_rewrites);
666+
self.node_rewrites.replace(node_rewrites);
671667
return if do_completed == DoCompleted::Yes { Some(vec![]) } else { None };
672668
}
673669

@@ -690,7 +686,7 @@ impl<O: ForestObligation> ObligationForest<O> {
690686
self.apply_rewrites(&node_rewrites);
691687

692688
node_rewrites.truncate(0);
693-
self.scratch.replace(node_rewrites);
689+
self.node_rewrites.replace(node_rewrites);
694690

695691
successful
696692
}

0 commit comments

Comments
 (0)