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

@ -8,6 +8,7 @@ publish = false
itertools = "0.7.8"
superslice = "0.1.0"
join_to_string = "0.1.1"
rustc-hash = "1.0"
ra_syntax = { path = "../ra_syntax" }

View file

@ -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<Completi
}
fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec<CompletionItem>) {
let mut params = HashMap::new();
let mut params = FxHashMap::default();
for node in ctx.ancestors() {
let _ = visitor_ctx(&mut params)
.visit::<ast::Root, _>(process)
@ -114,7 +114,7 @@ fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec<CompletionItem>) {
})
});
fn process<'a, N: ast::FnDefOwner<'a>>(node: N, params: &mut HashMap<String, (u32, ast::Param<'a>)>) {
fn process<'a, N: ast::FnDefOwner<'a>>(node: N, params: &mut FxHashMap<String, (u32, ast::Param<'a>)>) {
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<CompletionItem>) {
}
fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<CompletionItem>) {
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())

View file

@ -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<Fold> {
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<Fold> {
fn contiguous_range_for<'a>(
kind: SyntaxKind,
node: SyntaxNodeRef<'a>,
visited: &mut HashSet<SyntaxNodeRef<'a>>,
visited: &mut FxHashSet<SyntaxNodeRef<'a>>,
) -> Option<TextRange> {
visited.insert(node);

View file

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

View file

@ -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<SyntaxNode>,
scopes: Vec<ScopeData>,
scope_for: HashMap<SyntaxNode, ScopeId>,
scope_for: FxHashMap<SyntaxNode, ScopeId>,
}
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()))