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_lsp_server/Cargo.toml | 1 + crates/ra_lsp_server/src/lib.rs | 1 + crates/ra_lsp_server/src/main_loop/handlers.rs | 4 ++-- crates/ra_lsp_server/src/main_loop/mod.rs | 12 ++++++------ crates/ra_lsp_server/src/main_loop/subscriptions.rs | 6 +++--- crates/ra_lsp_server/src/project_model.rs | 6 +++--- crates/ra_lsp_server/src/req.rs | 4 ++-- crates/ra_lsp_server/src/server_world.rs | 8 ++++---- 8 files changed, 22 insertions(+), 20 deletions(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index 32463e499..1fe6b2ebe 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml @@ -21,6 +21,7 @@ im = "12.0.0" cargo_metadata = "0.6.0" text_unit = { version = "0.1.2", features = ["serde"] } smol_str = { version = "0.1.5", features = ["serde"] } +rustc-hash = "1.0" ra_syntax = { path = "../ra_syntax" } ra_editor = { path = "../ra_editor" } diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs index d2f76972f..60652d55e 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs @@ -16,6 +16,7 @@ extern crate walkdir; extern crate im; extern crate relative_path; extern crate cargo_metadata; +extern crate rustc_hash; extern crate gen_lsp_server; extern crate ra_editor; diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 725036cc7..ab8be15e9 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -1,4 +1,4 @@ -use std::collections::{HashMap}; +use rustc_hash::FxHashMap; use languageserver_types::{ Diagnostic, DiagnosticSeverity, DocumentSymbol, @@ -267,7 +267,7 @@ pub fn handle_runnables( bin: "cargo".to_string(), args, env: { - let mut m = HashMap::new(); + let mut m = FxHashMap::default(); m.insert( "RUST_BACKTRACE".to_string(), "short".to_string(), diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs index 53c6f1dff..402615e42 100644 --- a/crates/ra_lsp_server/src/main_loop/mod.rs +++ b/crates/ra_lsp_server/src/main_loop/mod.rs @@ -3,7 +3,6 @@ mod subscriptions; use std::{ path::PathBuf, - collections::{HashMap}, }; use serde::{Serialize, de::DeserializeOwned}; @@ -15,6 +14,7 @@ use gen_lsp_server::{ RawRequest, RawNotification, RawMessage, RawResponse, ErrorCode, handle_shutdown, }; +use rustc_hash::FxHashMap; use { req, @@ -50,7 +50,7 @@ pub fn main_loop( info!("server initialized, serving requests"); let mut state = ServerWorldState::new(); - let mut pending_requests = HashMap::new(); + let mut pending_requests = FxHashMap::default(); let mut subs = Subscriptions::new(); let main_res = main_loop_inner( internal_mode, @@ -95,7 +95,7 @@ fn main_loop_inner( fs_worker: Worker)>, ws_worker: Worker>, state: &mut ServerWorldState, - pending_requests: &mut HashMap, + pending_requests: &mut FxHashMap, subs: &mut Subscriptions, ) -> Result<()> { let (libdata_sender, libdata_receiver) = unbounded(); @@ -213,7 +213,7 @@ fn main_loop_inner( fn on_task( task: Task, msg_sender: &Sender, - pending_requests: &mut HashMap, + pending_requests: &mut FxHashMap, ) { match task { Task::Respond(response) => { @@ -229,7 +229,7 @@ fn on_task( fn on_request( world: &mut ServerWorldState, - pending_requests: &mut HashMap, + pending_requests: &mut FxHashMap, pool: &ThreadPool, sender: &Sender, req: RawRequest, @@ -269,7 +269,7 @@ fn on_request( fn on_notification( msg_sender: &Sender, state: &mut ServerWorldState, - pending_requests: &mut HashMap, + pending_requests: &mut FxHashMap, subs: &mut Subscriptions, not: RawNotification, ) -> Result<()> { diff --git a/crates/ra_lsp_server/src/main_loop/subscriptions.rs b/crates/ra_lsp_server/src/main_loop/subscriptions.rs index 27f92cc9a..310153382 100644 --- a/crates/ra_lsp_server/src/main_loop/subscriptions.rs +++ b/crates/ra_lsp_server/src/main_loop/subscriptions.rs @@ -1,13 +1,13 @@ -use std::collections::HashSet; +use rustc_hash::FxHashSet; use ra_analysis::FileId; pub struct Subscriptions { - subs: HashSet, + subs: FxHashSet, } impl Subscriptions { pub fn new() -> Subscriptions { - Subscriptions { subs: HashSet::new() } + Subscriptions { subs: FxHashSet::default() } } pub fn add_sub(&mut self, file_id: FileId) { self.subs.insert(file_id); diff --git a/crates/ra_lsp_server/src/project_model.rs b/crates/ra_lsp_server/src/project_model.rs index 5db34e3e5..43e4fd654 100644 --- a/crates/ra_lsp_server/src/project_model.rs +++ b/crates/ra_lsp_server/src/project_model.rs @@ -1,7 +1,7 @@ use std::{ - collections::{HashMap, HashSet}, path::{Path, PathBuf}, }; +use rustc_hash::{FxHashMap, FxHashSet}; use cargo_metadata::{metadata_run, CargoOpt}; use ra_syntax::SmolStr; @@ -80,11 +80,11 @@ impl CargoWorkspace { true, Some(CargoOpt::AllFeatures) ).map_err(|e| format_err!("cargo metadata failed: {}", e))?; - let mut pkg_by_id = HashMap::new(); + let mut pkg_by_id = FxHashMap::default(); let mut packages = Vec::new(); let mut targets = Vec::new(); - let ws_members: HashSet = meta.workspace_members + let ws_members: FxHashSet = meta.workspace_members .into_iter() .map(|it| it.raw) .collect(); diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index 458c79ea9..f80957589 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use rustc_hash::FxHashMap; use languageserver_types::{TextDocumentIdentifier, Range, Url, Position, Location}; use url_serde; @@ -149,7 +149,7 @@ pub struct Runnable { pub label: String, pub bin: String, pub args: Vec, - pub env: HashMap, + pub env: FxHashMap, } #[derive(Serialize, Debug)] diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 865f7c491..c4cdf83d4 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs @@ -1,10 +1,10 @@ use std::{ fs, path::{PathBuf, Path}, - collections::HashMap, sync::Arc, }; +use rustc_hash::FxHashMap; use languageserver_types::Url; use ra_analysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId, LibraryData, FileResolver}; @@ -20,7 +20,7 @@ pub struct ServerWorldState { pub workspaces: Arc>, pub analysis_host: AnalysisHost, pub path_map: PathMap, - pub mem_map: HashMap>, + pub mem_map: FxHashMap>, } #[derive(Clone)] @@ -36,7 +36,7 @@ impl ServerWorldState { workspaces: Arc::new(Vec::new()), analysis_host: AnalysisHost::new(), path_map: PathMap::new(), - mem_map: HashMap::new(), + mem_map: FxHashMap::default(), } } pub fn apply_fs_changes(&mut self, events: Vec) { @@ -121,7 +121,7 @@ impl ServerWorldState { Ok(file_id) } pub fn set_workspaces(&mut self, ws: Vec) { - let mut crate_roots = HashMap::new(); + let mut crate_roots = FxHashMap::default(); ws.iter() .flat_map(|ws| { ws.packages() -- cgit v1.2.3