Rollup merge of #55205 - ljedrz:faster_fxhashmap/set_population, r=estebank
Improve a few cases of collecting to an FxHash(Map/Set) Either use `collect` or procure specified capacity when possible.
This commit is contained in:
commit
62f4316b01
4 changed files with 15 additions and 19 deletions
|
@ -230,10 +230,7 @@ impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
|
||||||
type Node = Node;
|
type Node = Node;
|
||||||
type Edge = Edge<'tcx>;
|
type Edge = Edge<'tcx>;
|
||||||
fn nodes(&self) -> dot::Nodes<'_, Node> {
|
fn nodes(&self) -> dot::Nodes<'_, Node> {
|
||||||
let mut set = FxHashSet::default();
|
let set = self.node_ids.keys().cloned().collect::<FxHashSet<_>>();
|
||||||
for node in self.node_ids.keys() {
|
|
||||||
set.insert(*node);
|
|
||||||
}
|
|
||||||
debug!("constraint graph has {} nodes", set.len());
|
debug!("constraint graph has {} nodes", set.len());
|
||||||
set.into_iter().collect()
|
set.into_iter().collect()
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,12 +94,11 @@ pub enum Linkage {
|
||||||
|
|
||||||
pub fn calculate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
pub fn calculate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||||
let sess = &tcx.sess;
|
let sess = &tcx.sess;
|
||||||
let mut fmts = FxHashMap::default();
|
let fmts = sess.crate_types.borrow().iter().map(|&ty| {
|
||||||
for &ty in sess.crate_types.borrow().iter() {
|
|
||||||
let linkage = calculate_type(tcx, ty);
|
let linkage = calculate_type(tcx, ty);
|
||||||
verify_ok(tcx, &linkage);
|
verify_ok(tcx, &linkage);
|
||||||
fmts.insert(ty, linkage);
|
(ty, linkage)
|
||||||
}
|
}).collect::<FxHashMap<_, _>>();
|
||||||
sess.abort_if_errors();
|
sess.abort_if_errors();
|
||||||
sess.dependency_formats.set(fmts);
|
sess.dependency_formats.set(fmts);
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,10 +174,13 @@ impl<'sess> OnDiskCache<'sess> {
|
||||||
tcx.dep_graph.with_ignore(|| {
|
tcx.dep_graph.with_ignore(|| {
|
||||||
// Allocate SourceFileIndices
|
// Allocate SourceFileIndices
|
||||||
let (file_to_file_index, file_index_to_stable_id) = {
|
let (file_to_file_index, file_index_to_stable_id) = {
|
||||||
let mut file_to_file_index = FxHashMap::default();
|
let files = tcx.sess.source_map().files();
|
||||||
let mut file_index_to_stable_id = FxHashMap::default();
|
let mut file_to_file_index = FxHashMap::with_capacity_and_hasher(
|
||||||
|
files.len(), Default::default());
|
||||||
|
let mut file_index_to_stable_id = FxHashMap::with_capacity_and_hasher(
|
||||||
|
files.len(), Default::default());
|
||||||
|
|
||||||
for (index, file) in tcx.sess.source_map().files().iter().enumerate() {
|
for (index, file) in files.iter().enumerate() {
|
||||||
let index = SourceFileIndex(index as u32);
|
let index = SourceFileIndex(index as u32);
|
||||||
let file_ptr: *const SourceFile = &**file as *const _;
|
let file_ptr: *const SourceFile = &**file as *const _;
|
||||||
file_to_file_index.insert(file_ptr, index);
|
file_to_file_index.insert(file_ptr, index);
|
||||||
|
|
|
@ -3510,10 +3510,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
_ => span_bug!(span, "non-ADT passed to check_expr_struct_fields")
|
_ => span_bug!(span, "non-ADT passed to check_expr_struct_fields")
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut remaining_fields = FxHashMap::default();
|
let mut remaining_fields = variant.fields.iter().enumerate().map(|(i, field)|
|
||||||
for (i, field) in variant.fields.iter().enumerate() {
|
(field.ident.modern(), (i, field))
|
||||||
remaining_fields.insert(field.ident.modern(), (i, field));
|
).collect::<FxHashMap<_, _>>();
|
||||||
}
|
|
||||||
|
|
||||||
let mut seen_fields = FxHashMap::default();
|
let mut seen_fields = FxHashMap::default();
|
||||||
|
|
||||||
|
@ -5051,10 +5050,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
// provided (if any) into their appropriate spaces. We'll also report
|
// provided (if any) into their appropriate spaces. We'll also report
|
||||||
// errors if type parameters are provided in an inappropriate place.
|
// errors if type parameters are provided in an inappropriate place.
|
||||||
|
|
||||||
let mut generic_segs = FxHashSet::default();
|
let generic_segs = path_segs.iter().map(|PathSeg(_, index)| index)
|
||||||
for PathSeg(_, index) in &path_segs {
|
.collect::<FxHashSet<_>>();
|
||||||
generic_segs.insert(index);
|
|
||||||
}
|
|
||||||
AstConv::prohibit_generics(self, segments.iter().enumerate().filter_map(|(index, seg)| {
|
AstConv::prohibit_generics(self, segments.iter().enumerate().filter_map(|(index, seg)| {
|
||||||
if !generic_segs.contains(&index) {
|
if !generic_segs.contains(&index) {
|
||||||
Some(seg)
|
Some(seg)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue