Skip to content

Commit 18b1a6d

Browse files
committed
refactor: Remove unnecessary RefCell
1 parent 13a4bd4 commit 18b1a6d

File tree

1 file changed

+7
-6
lines changed
  • src/librustc_data_structures/obligation_forest

1 file changed

+7
-6
lines changed

src/librustc_data_structures/obligation_forest/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@
7474
7575
use crate::fx::{FxHashMap, FxHashSet};
7676

77-
use std::cell::{Cell, RefCell};
77+
use std::cell::Cell;
7878
use std::collections::hash_map::Entry;
7979
use std::fmt::Debug;
8080
use std::hash;
8181
use std::marker::PhantomData;
82+
use std::mem;
8283

8384
mod graphviz;
8485

@@ -143,7 +144,7 @@ pub struct ObligationForest<O: ForestObligation> {
143144
active_cache: FxHashMap<O::Predicate, Option<usize>>,
144145

145146
/// A vector reused in compress(), to avoid allocating new vectors.
146-
node_rewrites: RefCell<Vec<usize>>,
147+
node_rewrites: Vec<usize>,
147148

148149
obligation_tree_id_generator: ObligationTreeIdGenerator,
149150

@@ -281,7 +282,7 @@ impl<O: ForestObligation> ObligationForest<O> {
281282
ObligationForest {
282283
nodes: vec![],
283284
active_cache: Default::default(),
284-
node_rewrites: RefCell::new(vec![]),
285+
node_rewrites: vec![],
285286
obligation_tree_id_generator: (0..).map(ObligationTreeId),
286287
error_cache: Default::default(),
287288
}
@@ -587,7 +588,7 @@ impl<O: ForestObligation> ObligationForest<O> {
587588
fn compress(&mut self, do_completed: DoCompleted) -> Option<Vec<O>> {
588589
let orig_nodes_len = self.nodes.len();
589590
let remove_node_marker = orig_nodes_len + 1;
590-
let mut node_rewrites: Vec<_> = self.node_rewrites.replace(vec![]);
591+
let mut node_rewrites: Vec<_> = mem::take(&mut self.node_rewrites);
591592
debug_assert!(node_rewrites.is_empty());
592593
node_rewrites.extend(0..orig_nodes_len);
593594
let mut dead_nodes = 0;
@@ -636,8 +637,8 @@ impl<O: ForestObligation> ObligationForest<O> {
636637
self.apply_rewrites(&node_rewrites);
637638
}
638639

639-
node_rewrites.truncate(0);
640-
self.node_rewrites.replace(node_rewrites);
640+
node_rewrites.clear();
641+
self.node_rewrites = node_rewrites;
641642

642643
if do_completed == DoCompleted::Yes { Some(removed_done_obligations) } else { None }
643644
}

0 commit comments

Comments
 (0)