diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-11 19:28:44 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-11 19:28:44 +0100 |
commit | 2ba6f18586d02a6dbc32e0bea88f7b4236277ea1 (patch) | |
tree | 59bccb90d4b311ffd5c6adc5934fae91c0fb7740 /crates/ra_analysis/src | |
parent | 77e9bf9b5fdcd4262e2d9badb42b912f5728d90b (diff) | |
parent | dc2b30e9b6084048e441765b91ef830a836d3dfc (diff) |
Merge #122
122: Use rustc-hash crate r=matklad a=mominul
Replace std's HashMap, HashSet with FxHashMap and FxHashSet.
Closes #121
Thanks!
Co-authored-by: Muhammad Mominul Huque <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r-- | crates/ra_analysis/src/db/imp.rs | 9 | ||||
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 7 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 5 | ||||
-rw-r--r-- | crates/ra_analysis/src/roots.rs | 6 |
4 files changed, 15 insertions, 12 deletions
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::{ | |||
2 | sync::Arc, | 2 | sync::Arc, |
3 | any::Any, | 3 | any::Any, |
4 | hash::{Hash, Hasher}, | 4 | hash::{Hash, Hasher}, |
5 | collections::hash_map::{DefaultHasher, HashMap}, | 5 | collections::hash_map::{DefaultHasher}, |
6 | iter, | 6 | iter, |
7 | }; | 7 | }; |
8 | use rustc_hash::FxHashMap; | ||
8 | use salsa; | 9 | use salsa; |
9 | use {FileId, imp::FileResolverImp}; | 10 | use {FileId, imp::FileResolverImp}; |
10 | use super::{State, Query, QueryCtx}; | 11 | use super::{State, Query, QueryCtx}; |
@@ -13,7 +14,7 @@ pub(super) type Data = Arc<Any + Send + Sync + 'static>; | |||
13 | 14 | ||
14 | #[derive(Debug)] | 15 | #[derive(Debug)] |
15 | pub(super) struct Db { | 16 | pub(super) struct Db { |
16 | names: Arc<HashMap<salsa::QueryTypeId, &'static str>>, | 17 | names: Arc<FxHashMap<salsa::QueryTypeId, &'static str>>, |
17 | pub(super) imp: salsa::Db<State, Data>, | 18 | pub(super) imp: salsa::Db<State, Data>, |
18 | } | 19 | } |
19 | 20 | ||
@@ -85,7 +86,7 @@ where | |||
85 | 86 | ||
86 | pub(super) struct QueryRegistry { | 87 | pub(super) struct QueryRegistry { |
87 | config: Option<salsa::QueryConfig<State, Data>>, | 88 | config: Option<salsa::QueryConfig<State, Data>>, |
88 | names: HashMap<salsa::QueryTypeId, &'static str>, | 89 | names: FxHashMap<salsa::QueryTypeId, &'static str>, |
89 | } | 90 | } |
90 | 91 | ||
91 | impl QueryRegistry { | 92 | impl QueryRegistry { |
@@ -109,7 +110,7 @@ impl QueryRegistry { | |||
109 | (Arc::new(res), fingerprint) | 110 | (Arc::new(res), fingerprint) |
110 | }) | 111 | }) |
111 | ); | 112 | ); |
112 | let mut names = HashMap::new(); | 113 | let mut names = FxHashMap::default(); |
113 | names.insert(FILE_TEXT, "FILE_TEXT"); | 114 | names.insert(FILE_TEXT, "FILE_TEXT"); |
114 | names.insert(FILE_SET, "FILE_SET"); | 115 | names.insert(FILE_SET, "FILE_SET"); |
115 | QueryRegistry { config: Some(config), names } | 116 | 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::{ | |||
4 | atomic::{AtomicBool, Ordering::SeqCst}, | 4 | atomic::{AtomicBool, Ordering::SeqCst}, |
5 | }, | 5 | }, |
6 | fmt, | 6 | fmt, |
7 | collections::{HashSet, VecDeque}, | 7 | collections::VecDeque, |
8 | iter, | 8 | iter, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | use relative_path::RelativePath; | 11 | use relative_path::RelativePath; |
12 | use rustc_hash::FxHashSet; | ||
12 | use ra_editor::{self, FileSymbol, LineIndex, find_node_at_offset, LocalEdit, resolve_local_name}; | 13 | use ra_editor::{self, FileSymbol, LineIndex, find_node_at_offset, LocalEdit, resolve_local_name}; |
13 | use ra_syntax::{ | 14 | use ra_syntax::{ |
14 | TextUnit, TextRange, SmolStr, File, AstNode, | 15 | TextUnit, TextRange, SmolStr, File, AstNode, |
@@ -84,7 +85,7 @@ impl AnalysisHostImpl { | |||
84 | data.root = Arc::new(data.root.apply_changes(&mut iter::empty(), Some(resolver))); | 85 | data.root = Arc::new(data.root.apply_changes(&mut iter::empty(), Some(resolver))); |
85 | } | 86 | } |
86 | pub fn set_crate_graph(&mut self, graph: CrateGraph) { | 87 | pub fn set_crate_graph(&mut self, graph: CrateGraph) { |
87 | let mut visited = HashSet::new(); | 88 | let mut visited = FxHashSet::default(); |
88 | for &file_id in graph.crate_roots.values() { | 89 | for &file_id in graph.crate_roots.values() { |
89 | if !visited.insert(file_id) { | 90 | if !visited.insert(file_id) { |
90 | panic!("duplicate crate root: {:?}", file_id); | 91 | panic!("duplicate crate root: {:?}", file_id); |
@@ -168,7 +169,7 @@ impl AnalysisImpl { | |||
168 | let mut res = Vec::new(); | 169 | let mut res = Vec::new(); |
169 | let mut work = VecDeque::new(); | 170 | let mut work = VecDeque::new(); |
170 | work.push_back(file_id); | 171 | work.push_back(file_id); |
171 | let mut visited = HashSet::new(); | 172 | let mut visited = FxHashSet::default(); |
172 | while let Some(id) = work.pop_front() { | 173 | while let Some(id) = work.pop_front() { |
173 | if let Some(crate_id) = crate_graph.crate_id_for_crate_root(id) { | 174 | if let Some(crate_id) = crate_graph.crate_id_for_crate_root(id) { |
174 | res.push(crate_id); | 175 | 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; | |||
11 | extern crate crossbeam_channel; | 11 | extern crate crossbeam_channel; |
12 | extern crate im; | 12 | extern crate im; |
13 | extern crate salsa; | 13 | extern crate salsa; |
14 | extern crate rustc_hash; | ||
14 | 15 | ||
15 | mod symbol_index; | 16 | mod symbol_index; |
16 | mod module_map; | 17 | mod module_map; |
@@ -23,13 +24,13 @@ mod descriptors; | |||
23 | 24 | ||
24 | use std::{ | 25 | use std::{ |
25 | sync::Arc, | 26 | sync::Arc, |
26 | collections::HashMap, | ||
27 | fmt::Debug, | 27 | fmt::Debug, |
28 | }; | 28 | }; |
29 | 29 | ||
30 | use relative_path::{RelativePath, RelativePathBuf}; | 30 | use relative_path::{RelativePath, RelativePathBuf}; |
31 | use ra_syntax::{File, TextRange, TextUnit, AtomEdit}; | 31 | use ra_syntax::{File, TextRange, TextUnit, AtomEdit}; |
32 | use imp::{AnalysisImpl, AnalysisHostImpl, FileResolverImp}; | 32 | use imp::{AnalysisImpl, AnalysisHostImpl, FileResolverImp}; |
33 | use rustc_hash::FxHashMap; | ||
33 | 34 | ||
34 | pub use ra_editor::{ | 35 | pub use ra_editor::{ |
35 | StructureNode, LineIndex, FileSymbol, | 36 | StructureNode, LineIndex, FileSymbol, |
@@ -46,7 +47,7 @@ pub struct CrateId(pub u32); | |||
46 | 47 | ||
47 | #[derive(Debug, Clone, Default)] | 48 | #[derive(Debug, Clone, Default)] |
48 | pub struct CrateGraph { | 49 | pub struct CrateGraph { |
49 | pub crate_roots: HashMap<CrateId, FileId>, | 50 | pub crate_roots: FxHashMap<CrateId, FileId>, |
50 | } | 51 | } |
51 | 52 | ||
52 | pub trait FileResolver: Debug + Send + Sync + 'static { | 53 | 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 @@ | |||
1 | use std::{ | 1 | use std::{ |
2 | collections::HashMap, | ||
3 | sync::Arc, | 2 | sync::Arc, |
4 | panic, | 3 | panic, |
5 | }; | 4 | }; |
6 | 5 | ||
7 | use once_cell::sync::OnceCell; | 6 | use once_cell::sync::OnceCell; |
8 | use rayon::prelude::*; | 7 | use rayon::prelude::*; |
8 | use rustc_hash::FxHashMap; | ||
9 | use ra_editor::LineIndex; | 9 | use ra_editor::LineIndex; |
10 | use ra_syntax::File; | 10 | use ra_syntax::File; |
11 | 11 | ||
@@ -118,7 +118,7 @@ impl FileData { | |||
118 | #[derive(Debug)] | 118 | #[derive(Debug)] |
119 | pub(crate) struct ReadonlySourceRoot { | 119 | pub(crate) struct ReadonlySourceRoot { |
120 | symbol_index: Arc<SymbolIndex>, | 120 | symbol_index: Arc<SymbolIndex>, |
121 | file_map: HashMap<FileId, FileData>, | 121 | file_map: FxHashMap<FileId, FileData>, |
122 | module_tree: Arc<ModuleTreeDescriptor>, | 122 | module_tree: Arc<ModuleTreeDescriptor>, |
123 | } | 123 | } |
124 | 124 | ||
@@ -139,7 +139,7 @@ impl ReadonlySourceRoot { | |||
139 | let symbol_index = SymbolIndex::for_files( | 139 | let symbol_index = SymbolIndex::for_files( |
140 | modules.par_iter().map(|it| (it.0, it.1.clone())) | 140 | modules.par_iter().map(|it| (it.0, it.1.clone())) |
141 | ); | 141 | ); |
142 | let file_map: HashMap<FileId, FileData> = files | 142 | let file_map: FxHashMap<FileId, FileData> = files |
143 | .into_iter() | 143 | .into_iter() |
144 | .map(|(id, text)| (id, FileData::new(text))) | 144 | .map(|(id, text)| (id, FileData::new(text))) |
145 | .collect(); | 145 | .collect(); |