Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve a few cases of collecting to an FxHash(Map/Set) #55205

Merged
merged 1 commit into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/librustc/infer/lexical_region_resolve/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/middle/dependency_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 6 additions & 3 deletions src/librustc/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 5 additions & 8 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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)
Expand Down