Skip to content

Commit 70b136d

Browse files
committed
Use a BitSet in LexicalResolver::iterate_until_fixed_point().
This wins 3% on `unicode_normalization`.
1 parent 53aca55 commit 70b136d

File tree

1 file changed

+18
-5
lines changed
  • src/librustc/infer/lexical_region_resolve

1 file changed

+18
-5
lines changed

src/librustc/infer/lexical_region_resolve/mod.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use rustc_data_structures::fx::FxHashSet;
1919
use rustc_data_structures::graph::implementation::{
2020
Direction, Graph, NodeIndex, INCOMING, OUTGOING,
2121
};
22+
use rustc_index::bit_set::BitSet;
2223
use rustc_index::vec::{Idx, IndexVec};
23-
use smallvec::SmallVec;
2424
use std::fmt;
2525
use syntax_pos::Span;
2626

@@ -870,21 +870,34 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
870870
where
871871
F: FnMut(&Constraint<'tcx>) -> (bool, bool),
872872
{
873-
let mut constraints: SmallVec<[_; 16]> = self.data.constraints.keys().collect();
873+
// Using bitsets to track the remaining elements is faster than using a
874+
// `Vec` by itself (which requires removing elements, which requires
875+
// element shuffling, which is slow).
876+
let constraints: Vec<_> = self.data.constraints.keys().collect();
877+
let mut live_indices: BitSet<usize> = BitSet::new_filled(constraints.len());
878+
let mut killed_indices: BitSet<usize> = BitSet::new_empty(constraints.len());
874879
let mut iteration = 0;
875880
let mut changed = true;
876881
while changed {
877882
changed = false;
878883
iteration += 1;
879884
debug!("---- Expansion iteration {}", iteration);
880-
constraints.retain(|constraint| {
885+
for index in live_indices.iter() {
886+
let constraint = constraints[index];
881887
let (edge_changed, retain) = body(constraint);
882888
if edge_changed {
883889
debug!("updated due to constraint {:?}", constraint);
884890
changed = true;
885891
}
886-
retain
887-
});
892+
if !retain {
893+
let changed = killed_indices.insert(index);
894+
debug_assert!(changed);
895+
}
896+
}
897+
live_indices.subtract(&killed_indices);
898+
899+
// We could clear `killed_indices` here, but we don't need to and
900+
// it's cheaper not to.
888901
}
889902
debug!("---- Expansion complete after {} iteration(s)", iteration);
890903
}

0 commit comments

Comments
 (0)