Replace HashMap, HashSet with FxHashMap and FxHashSet

This commit is contained in:
Muhammad Mominul Huque 2018-10-12 00:07:44 +06:00
parent 9b155c8976
commit dc2b30e9b6
No known key found for this signature in database
GPG key ID: 9D472E8B36098956
20 changed files with 68 additions and 49 deletions

View file

@ -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;

View file

@ -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(),

View file

@ -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<PathBuf, (PathBuf, Vec<FileEvent>)>,
ws_worker: Worker<PathBuf, Result<CargoWorkspace>>,
state: &mut ServerWorldState,
pending_requests: &mut HashMap<u64, JobHandle>,
pending_requests: &mut FxHashMap<u64, JobHandle>,
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<RawMessage>,
pending_requests: &mut HashMap<u64, JobHandle>,
pending_requests: &mut FxHashMap<u64, JobHandle>,
) {
match task {
Task::Respond(response) => {
@ -229,7 +229,7 @@ fn on_task(
fn on_request(
world: &mut ServerWorldState,
pending_requests: &mut HashMap<u64, JobHandle>,
pending_requests: &mut FxHashMap<u64, JobHandle>,
pool: &ThreadPool,
sender: &Sender<Task>,
req: RawRequest,
@ -269,7 +269,7 @@ fn on_request(
fn on_notification(
msg_sender: &Sender<RawMessage>,
state: &mut ServerWorldState,
pending_requests: &mut HashMap<u64, JobHandle>,
pending_requests: &mut FxHashMap<u64, JobHandle>,
subs: &mut Subscriptions,
not: RawNotification,
) -> Result<()> {

View file

@ -1,13 +1,13 @@
use std::collections::HashSet;
use rustc_hash::FxHashSet;
use ra_analysis::FileId;
pub struct Subscriptions {
subs: HashSet<FileId>,
subs: FxHashSet<FileId>,
}
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);

View file

@ -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<String> = meta.workspace_members
let ws_members: FxHashSet<String> = meta.workspace_members
.into_iter()
.map(|it| it.raw)
.collect();

View file

@ -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<String>,
pub env: HashMap<String, String>,
pub env: FxHashMap<String, String>,
}
#[derive(Serialize, Debug)]

View file

@ -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<Vec<CargoWorkspace>>,
pub analysis_host: AnalysisHost,
pub path_map: PathMap,
pub mem_map: HashMap<FileId, Option<String>>,
pub mem_map: FxHashMap<FileId, Option<String>>,
}
#[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<FileEvent>) {
@ -121,7 +121,7 @@ impl ServerWorldState {
Ok(file_id)
}
pub fn set_workspaces(&mut self, ws: Vec<CargoWorkspace>) {
let mut crate_roots = HashMap::new();
let mut crate_roots = FxHashMap::default();
ws.iter()
.flat_map(|ws| {
ws.packages()