From dc2b30e9b6084048e441765b91ef830a836d3dfc Mon Sep 17 00:00:00 2001 From: Muhammad Mominul Huque Date: Fri, 12 Oct 2018 00:07:44 +0600 Subject: Replace HashMap, HashSet with FxHashMap and FxHashSet --- crates/ra_analysis/src/db/imp.rs | 9 +++++---- crates/ra_analysis/src/imp.rs | 7 ++++--- crates/ra_analysis/src/lib.rs | 5 +++-- crates/ra_analysis/src/roots.rs | 6 +++--- 4 files changed, 15 insertions(+), 12 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/db/imp.rs b/crates/ra_analysis/src/db/imp.rs index f26be1046..36f6cf290 100644 --- a/crates/ra_analysis/src/db/imp.rs +++ b/crates/ra_analysis/src/db/imp.rs @@ -2,9 +2,10 @@ use std::{ sync::Arc, any::Any, hash::{Hash, Hasher}, - collections::hash_map::{DefaultHasher, HashMap}, + collections::hash_map::{DefaultHasher}, iter, }; +use rustc_hash::FxHashMap; use salsa; use {FileId, imp::FileResolverImp}; use super::{State, Query, QueryCtx}; @@ -13,7 +14,7 @@ pub(super) type Data = Arc; #[derive(Debug)] pub(super) struct Db { - names: Arc>, + names: Arc>, pub(super) imp: salsa::Db, } @@ -85,7 +86,7 @@ where pub(super) struct QueryRegistry { config: Option>, - names: HashMap, + names: FxHashMap, } impl QueryRegistry { @@ -109,7 +110,7 @@ impl QueryRegistry { (Arc::new(res), fingerprint) }) ); - let mut names = HashMap::new(); + let mut names = FxHashMap::default(); names.insert(FILE_TEXT, "FILE_TEXT"); names.insert(FILE_SET, "FILE_SET"); QueryRegistry { config: Some(config), names } diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 517867e86..47bc0032b 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -4,11 +4,12 @@ use std::{ atomic::{AtomicBool, Ordering::SeqCst}, }, fmt, - collections::{HashSet, VecDeque}, + collections::VecDeque, iter, }; use relative_path::RelativePath; +use rustc_hash::FxHashSet; use ra_editor::{self, FileSymbol, LineIndex, find_node_at_offset, LocalEdit, resolve_local_name}; use ra_syntax::{ TextUnit, TextRange, SmolStr, File, AstNode, @@ -84,7 +85,7 @@ impl AnalysisHostImpl { data.root = Arc::new(data.root.apply_changes(&mut iter::empty(), Some(resolver))); } pub fn set_crate_graph(&mut self, graph: CrateGraph) { - let mut visited = HashSet::new(); + let mut visited = FxHashSet::default(); for &file_id in graph.crate_roots.values() { if !visited.insert(file_id) { panic!("duplicate crate root: {:?}", file_id); @@ -168,7 +169,7 @@ impl AnalysisImpl { let mut res = Vec::new(); let mut work = VecDeque::new(); work.push_back(file_id); - let mut visited = HashSet::new(); + let mut visited = FxHashSet::default(); while let Some(id) = work.pop_front() { if let Some(crate_id) = crate_graph.crate_id_for_crate_root(id) { res.push(crate_id); diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index f6ceb7eb2..849fd93e4 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -11,6 +11,7 @@ extern crate relative_path; extern crate crossbeam_channel; extern crate im; extern crate salsa; +extern crate rustc_hash; mod symbol_index; mod module_map; @@ -23,13 +24,13 @@ mod descriptors; use std::{ sync::Arc, - collections::HashMap, fmt::Debug, }; use relative_path::{RelativePath, RelativePathBuf}; use ra_syntax::{File, TextRange, TextUnit, AtomEdit}; use imp::{AnalysisImpl, AnalysisHostImpl, FileResolverImp}; +use rustc_hash::FxHashMap; pub use ra_editor::{ StructureNode, LineIndex, FileSymbol, @@ -46,7 +47,7 @@ pub struct CrateId(pub u32); #[derive(Debug, Clone, Default)] pub struct CrateGraph { - pub crate_roots: HashMap, + pub crate_roots: FxHashMap, } pub trait FileResolver: Debug + Send + Sync + 'static { diff --git a/crates/ra_analysis/src/roots.rs b/crates/ra_analysis/src/roots.rs index 1835a9b25..32a8c5bd0 100644 --- a/crates/ra_analysis/src/roots.rs +++ b/crates/ra_analysis/src/roots.rs @@ -1,11 +1,11 @@ use std::{ - collections::HashMap, sync::Arc, panic, }; use once_cell::sync::OnceCell; use rayon::prelude::*; +use rustc_hash::FxHashMap; use ra_editor::LineIndex; use ra_syntax::File; @@ -118,7 +118,7 @@ impl FileData { #[derive(Debug)] pub(crate) struct ReadonlySourceRoot { symbol_index: Arc, - file_map: HashMap, + file_map: FxHashMap, module_tree: Arc, } @@ -139,7 +139,7 @@ impl ReadonlySourceRoot { let symbol_index = SymbolIndex::for_files( modules.par_iter().map(|it| (it.0, it.1.clone())) ); - let file_map: HashMap = files + let file_map: FxHashMap = files .into_iter() .map(|(id, text)| (id, FileData::new(text))) .collect(); -- cgit v1.2.3