mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Replace HashMap, HashSet with FxHashMap and FxHashSet
This commit is contained in:
parent
9b155c8976
commit
dc2b30e9b6
20 changed files with 68 additions and 49 deletions
|
@ -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<Any + Send + Sync + 'static>;
|
|||
|
||||
#[derive(Debug)]
|
||||
pub(super) struct Db {
|
||||
names: Arc<HashMap<salsa::QueryTypeId, &'static str>>,
|
||||
names: Arc<FxHashMap<salsa::QueryTypeId, &'static str>>,
|
||||
pub(super) imp: salsa::Db<State, Data>,
|
||||
}
|
||||
|
||||
|
@ -85,7 +86,7 @@ where
|
|||
|
||||
pub(super) struct QueryRegistry {
|
||||
config: Option<salsa::QueryConfig<State, Data>>,
|
||||
names: HashMap<salsa::QueryTypeId, &'static str>,
|
||||
names: FxHashMap<salsa::QueryTypeId, &'static str>,
|
||||
}
|
||||
|
||||
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 }
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<CrateId, FileId>,
|
||||
pub crate_roots: FxHashMap<CrateId, FileId>,
|
||||
}
|
||||
|
||||
pub trait FileResolver: Debug + Send + Sync + 'static {
|
||||
|
|
|
@ -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<SymbolIndex>,
|
||||
file_map: HashMap<FileId, FileData>,
|
||||
file_map: FxHashMap<FileId, FileData>,
|
||||
module_tree: Arc<ModuleTreeDescriptor>,
|
||||
}
|
||||
|
||||
|
@ -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<FileId, FileData> = files
|
||||
let file_map: FxHashMap<FileId, FileData> = files
|
||||
.into_iter()
|
||||
.map(|(id, text)| (id, FileData::new(text)))
|
||||
.collect();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue