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_editor/src/completion.rs | 8 ++++---- crates/ra_editor/src/folding_ranges.rs | 6 +++--- crates/ra_editor/src/lib.rs | 1 + crates/ra_editor/src/scope/fn_scope.rs | 14 ++++++-------- 4 files changed, 14 insertions(+), 15 deletions(-) (limited to 'crates/ra_editor/src') diff --git a/crates/ra_editor/src/completion.rs b/crates/ra_editor/src/completion.rs index 570d72d66..20b8484b3 100644 --- a/crates/ra_editor/src/completion.rs +++ b/crates/ra_editor/src/completion.rs @@ -1,4 +1,4 @@ -use std::collections::{HashSet, HashMap}; +use rustc_hash::{FxHashMap, FxHashSet}; use ra_syntax::{ File, TextUnit, AstNode, SyntaxNodeRef, SyntaxKind::*, @@ -96,7 +96,7 @@ fn complete_name_ref(file: &File, name_ref: ast::NameRef, acc: &mut Vec) { - let mut params = HashMap::new(); + let mut params = FxHashMap::default(); for node in ctx.ancestors() { let _ = visitor_ctx(&mut params) .visit::(process) @@ -114,7 +114,7 @@ fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec) { }) }); - fn process<'a, N: ast::FnDefOwner<'a>>(node: N, params: &mut HashMap)>) { + fn process<'a, N: ast::FnDefOwner<'a>>(node: N, params: &mut FxHashMap)>) { node.functions() .filter_map(|it| it.param_list()) .flat_map(|it| it.params()) @@ -232,7 +232,7 @@ fn complete_mod_item_snippets(acc: &mut Vec) { } fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec) { - let mut shadowed = HashSet::new(); + let mut shadowed = FxHashSet::default(); acc.extend( scopes.scope_chain(name_ref.syntax()) .flat_map(|scope| scopes.entries(scope).iter()) diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs index 733512368..3aabd54ae 100644 --- a/crates/ra_editor/src/folding_ranges.rs +++ b/crates/ra_editor/src/folding_ranges.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use rustc_hash::FxHashSet; use ra_syntax::{ File, TextRange, SyntaxNodeRef, @@ -20,7 +20,7 @@ pub struct Fold { pub fn folding_ranges(file: &File) -> Vec { let mut res = vec![]; - let mut visited = HashSet::new(); + let mut visited = FxHashSet::default(); for node in file.syntax().descendants() { if visited.contains(&node) { @@ -56,7 +56,7 @@ pub fn folding_ranges(file: &File) -> Vec { fn contiguous_range_for<'a>( kind: SyntaxKind, node: SyntaxNodeRef<'a>, - visited: &mut HashSet>, + visited: &mut FxHashSet>, ) -> Option { visited.insert(node); diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs index 906ee11fe..710afc65d 100644 --- a/crates/ra_editor/src/lib.rs +++ b/crates/ra_editor/src/lib.rs @@ -2,6 +2,7 @@ extern crate ra_syntax; extern crate superslice; extern crate itertools; extern crate join_to_string; +extern crate rustc_hash; #[cfg(test)] #[macro_use] extern crate test_utils as _test_utils; diff --git a/crates/ra_editor/src/scope/fn_scope.rs b/crates/ra_editor/src/scope/fn_scope.rs index 65d85279f..9a48bda02 100644 --- a/crates/ra_editor/src/scope/fn_scope.rs +++ b/crates/ra_editor/src/scope/fn_scope.rs @@ -1,7 +1,5 @@ -use std::{ - fmt, - collections::HashMap, -}; +use std::fmt; +use rustc_hash::FxHashMap; use ra_syntax::{ SyntaxNodeRef, SyntaxNode, SmolStr, AstNode, @@ -15,7 +13,7 @@ type ScopeId = usize; pub struct FnScopes { pub self_param: Option, scopes: Vec, - scope_for: HashMap, + scope_for: FxHashMap, } impl FnScopes { @@ -25,7 +23,7 @@ impl FnScopes { .and_then(|it| it.self_param()) .map(|it| it.syntax().owned()), scopes: Vec::new(), - scope_for: HashMap::new() + scope_for: FxHashMap::default() }; let root = scopes.root_scope(); scopes.add_params_bindings(root, fn_def.param_list()); @@ -242,9 +240,9 @@ struct ScopeData { } pub fn resolve_local_name<'a>(name_ref: ast::NameRef, scopes: &'a FnScopes) -> Option<&'a ScopeEntry> { - use std::collections::HashSet; + use rustc_hash::FxHashSet; - let mut shadowed = HashSet::new(); + let mut shadowed = FxHashSet::default(); let ret = scopes.scope_chain(name_ref.syntax()) .flat_map(|scope| scopes.entries(scope).iter()) .filter(|entry| shadowed.insert(entry.name())) -- cgit v1.2.3