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 Edge = Edge<'tcx>;
|
||||
fn nodes(&self) -> dot::Nodes<'_, Node> {
|
||||
let mut set = FxHashSet::default();
|
||||
for node in self.node_ids.keys() {
|
||||
set.insert(*node);
|
||||
}
|
||||
let set = self.node_ids.keys().cloned().collect::<FxHashSet<_>>();
|
||||
debug!("constraint graph has {} nodes", set.len());
|
||||
set.into_iter().collect()
|
||||
}
|
||||
|
|
|
@ -94,12 +94,11 @@ pub enum Linkage {
|
|||
|
||||
pub fn calculate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
let sess = &tcx.sess;
|
||||
let mut fmts = FxHashMap::default();
|
||||
for &ty in sess.crate_types.borrow().iter() {
|
||||
let fmts = sess.crate_types.borrow().iter().map(|&ty| {
|
||||
let linkage = calculate_type(tcx, ty);
|
||||
verify_ok(tcx, &linkage);
|
||||
fmts.insert(ty, linkage);
|
||||
}
|
||||
(ty, linkage)
|
||||
}).collect::<FxHashMap<_, _>>();
|
||||
sess.abort_if_errors();
|
||||
sess.dependency_formats.set(fmts);
|
||||
}
|
||||
|
|
|
@ -174,10 +174,13 @@ impl<'sess> OnDiskCache<'sess> {
|
|||
tcx.dep_graph.with_ignore(|| {
|
||||
// Allocate SourceFileIndices
|
||||
let (file_to_file_index, file_index_to_stable_id) = {
|
||||
let mut file_to_file_index = FxHashMap::default();
|
||||
let mut file_index_to_stable_id = FxHashMap::default();
|
||||
let files = tcx.sess.source_map().files();
|
||||
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 file_ptr: *const SourceFile = &**file as *const _;
|
||||
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")
|
||||
};
|
||||
|
||||
let mut remaining_fields = FxHashMap::default();
|
||||
for (i, field) in variant.fields.iter().enumerate() {
|
||||
remaining_fields.insert(field.ident.modern(), (i, field));
|
||||
}
|
||||
let mut remaining_fields = variant.fields.iter().enumerate().map(|(i, field)|
|
||||
(field.ident.modern(), (i, field))
|
||||
).collect::<FxHashMap<_, _>>();
|
||||
|
||||
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
|
||||
// errors if type parameters are provided in an inappropriate place.
|
||||
|
||||
let mut generic_segs = FxHashSet::default();
|
||||
for PathSeg(_, index) in &path_segs {
|
||||
generic_segs.insert(index);
|
||||
}
|
||||
let generic_segs = path_segs.iter().map(|PathSeg(_, index)| index)
|
||||
.collect::<FxHashSet<_>>();
|
||||
AstConv::prohibit_generics(self, segments.iter().enumerate().filter_map(|(index, seg)| {
|
||||
if !generic_segs.contains(&index) {
|
||||
Some(seg)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue