aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenČ›iu Nicola <[email protected]>2020-06-29 16:07:52 +0100
committerLaurenČ›iu Nicola <[email protected]>2020-06-29 16:07:52 +0100
commit95d67ec40174ec1c344ab39eee414d7a41a36af0 (patch)
tree43f713aef65a1439b960b1d199863dc1c29a1994
parent82ce5792ab70ab8d20a1afde72c5400c27b9c190 (diff)
Use more of FxHash*
-rw-r--r--crates/ra_assists/src/handlers/reorder_fields.rs6
-rw-r--r--crates/ra_ssr/src/parsing.rs2
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs10
-rw-r--r--crates/rust-analyzer/src/cli/diagnostics.rs7
-rw-r--r--crates/rust-analyzer/src/diagnostics.rs10
-rw-r--r--docs/dev/README.md5
6 files changed, 25 insertions, 15 deletions
diff --git a/crates/ra_assists/src/handlers/reorder_fields.rs b/crates/ra_assists/src/handlers/reorder_fields.rs
index 897da2832..bc58ce5fe 100644
--- a/crates/ra_assists/src/handlers/reorder_fields.rs
+++ b/crates/ra_assists/src/handlers/reorder_fields.rs
@@ -1,7 +1,7 @@
1use std::collections::HashMap; 1use itertools::Itertools;
2use rustc_hash::FxHashMap;
2 3
3use hir::{Adt, ModuleDef, PathResolution, Semantics, Struct}; 4use hir::{Adt, ModuleDef, PathResolution, Semantics, Struct};
4use itertools::Itertools;
5use ra_ide_db::RootDatabase; 5use ra_ide_db::RootDatabase;
6use ra_syntax::{algo, ast, match_ast, AstNode, SyntaxKind, SyntaxKind::*, SyntaxNode}; 6use ra_syntax::{algo, ast, match_ast, AstNode, SyntaxKind, SyntaxKind::*, SyntaxNode};
7 7
@@ -87,7 +87,7 @@ fn struct_definition(path: &ast::Path, sema: &Semantics<RootDatabase>) -> Option
87 } 87 }
88} 88}
89 89
90fn compute_fields_ranks(path: &ast::Path, ctx: &AssistContext) -> Option<HashMap<String, usize>> { 90fn compute_fields_ranks(path: &ast::Path, ctx: &AssistContext) -> Option<FxHashMap<String, usize>> {
91 Some( 91 Some(
92 struct_definition(path, &ctx.sema)? 92 struct_definition(path, &ctx.sema)?
93 .fields(ctx.db) 93 .fields(ctx.db)
diff --git a/crates/ra_ssr/src/parsing.rs b/crates/ra_ssr/src/parsing.rs
index 90c13dbc2..1ae166d19 100644
--- a/crates/ra_ssr/src/parsing.rs
+++ b/crates/ra_ssr/src/parsing.rs
@@ -165,7 +165,7 @@ fn parse_pattern(pattern_str: &str) -> Result<Vec<PatternElement>, SsrError> {
165/// Checks for errors in a rule. e.g. the replace pattern referencing placeholders that the search 165/// Checks for errors in a rule. e.g. the replace pattern referencing placeholders that the search
166/// pattern didn't define. 166/// pattern didn't define.
167fn validate_rule(rule: &SsrRule) -> Result<(), SsrError> { 167fn validate_rule(rule: &SsrRule) -> Result<(), SsrError> {
168 let mut defined_placeholders = std::collections::HashSet::new(); 168 let mut defined_placeholders = FxHashSet::default();
169 for p in &rule.pattern.raw.tokens { 169 for p in &rule.pattern.raw.tokens {
170 if let PatternElement::Placeholder(placeholder) = p { 170 if let PatternElement::Placeholder(placeholder) = p {
171 defined_placeholders.insert(&placeholder.ident); 171 defined_placeholders.insert(&placeholder.ident);
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index 2f4c29e06..9d09501cd 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -1,7 +1,11 @@
1//! Fully type-check project and print various stats, like the number of type 1//! Fully type-check project and print various stats, like the number of type
2//! errors. 2//! errors.
3 3
4use std::{collections::HashSet, path::Path, time::Instant}; 4use std::{path::Path, time::Instant};
5
6use itertools::Itertools;
7use rand::{seq::SliceRandom, thread_rng};
8use rustc_hash::FxHashSet;
5 9
6use hir::{ 10use hir::{
7 db::{AstDatabase, DefDatabase, HirDatabase}, 11 db::{AstDatabase, DefDatabase, HirDatabase},
@@ -9,10 +13,8 @@ use hir::{
9}; 13};
10use hir_def::FunctionId; 14use hir_def::FunctionId;
11use hir_ty::{Ty, TypeWalk}; 15use hir_ty::{Ty, TypeWalk};
12use itertools::Itertools;
13use ra_db::SourceDatabaseExt; 16use ra_db::SourceDatabaseExt;
14use ra_syntax::AstNode; 17use ra_syntax::AstNode;
15use rand::{seq::SliceRandom, thread_rng};
16use stdx::format_to; 18use stdx::format_to;
17 19
18use crate::cli::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity}; 20use crate::cli::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity};
@@ -33,7 +35,7 @@ pub fn analysis_stats(
33 println!("Database loaded {:?}", db_load_time.elapsed()); 35 println!("Database loaded {:?}", db_load_time.elapsed());
34 let analysis_time = Instant::now(); 36 let analysis_time = Instant::now();
35 let mut num_crates = 0; 37 let mut num_crates = 0;
36 let mut visited_modules = HashSet::new(); 38 let mut visited_modules = FxHashSet::default();
37 let mut visit_queue = Vec::new(); 39 let mut visit_queue = Vec::new();
38 40
39 let mut krates = Crate::all(db); 41 let mut krates = Crate::all(db);
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs
index 82b3a8a53..6f3c1c1f9 100644
--- a/crates/rust-analyzer/src/cli/diagnostics.rs
+++ b/crates/rust-analyzer/src/cli/diagnostics.rs
@@ -1,11 +1,14 @@
1//! Analyze all modules in a project for diagnostics. Exits with a non-zero status 1//! Analyze all modules in a project for diagnostics. Exits with a non-zero status
2//! code if any errors are found. 2//! code if any errors are found.
3 3
4use std::path::Path;
5
4use anyhow::anyhow; 6use anyhow::anyhow;
7use rustc_hash::FxHashSet;
8
5use hir::Crate; 9use hir::Crate;
6use ra_db::SourceDatabaseExt; 10use ra_db::SourceDatabaseExt;
7use ra_ide::Severity; 11use ra_ide::Severity;
8use std::{collections::HashSet, path::Path};
9 12
10use crate::cli::{load_cargo::load_cargo, Result}; 13use crate::cli::{load_cargo::load_cargo, Result};
11 14
@@ -20,7 +23,7 @@ pub fn diagnostics(
20 let analysis = host.analysis(); 23 let analysis = host.analysis();
21 24
22 let mut found_error = false; 25 let mut found_error = false;
23 let mut visited_files = HashSet::new(); 26 let mut visited_files = FxHashSet::default();
24 27
25 let mut work = Vec::new(); 28 let mut work = Vec::new();
26 let krates = Crate::all(db); 29 let krates = Crate::all(db);
diff --git a/crates/rust-analyzer/src/diagnostics.rs b/crates/rust-analyzer/src/diagnostics.rs
index 1cf50b677..b46281c98 100644
--- a/crates/rust-analyzer/src/diagnostics.rs
+++ b/crates/rust-analyzer/src/diagnostics.rs
@@ -1,14 +1,14 @@
1//! Book keeping for keeping diagnostics easily in sync with the client. 1//! Book keeping for keeping diagnostics easily in sync with the client.
2pub(crate) mod to_proto; 2pub(crate) mod to_proto;
3 3
4use std::{collections::HashMap, mem, sync::Arc}; 4use std::{mem, sync::Arc};
5 5
6use ra_ide::FileId; 6use ra_ide::FileId;
7use rustc_hash::FxHashSet; 7use rustc_hash::{FxHashMap, FxHashSet};
8 8
9use crate::lsp_ext; 9use crate::lsp_ext;
10 10
11pub(crate) type CheckFixes = Arc<HashMap<FileId, Vec<Fix>>>; 11pub(crate) type CheckFixes = Arc<FxHashMap<FileId, Vec<Fix>>>;
12 12
13#[derive(Debug, Default, Clone)] 13#[derive(Debug, Default, Clone)]
14pub struct DiagnosticsConfig { 14pub struct DiagnosticsConfig {
@@ -18,8 +18,8 @@ pub struct DiagnosticsConfig {
18 18
19#[derive(Debug, Default, Clone)] 19#[derive(Debug, Default, Clone)]
20pub(crate) struct DiagnosticCollection { 20pub(crate) struct DiagnosticCollection {
21 pub(crate) native: HashMap<FileId, Vec<lsp_types::Diagnostic>>, 21 pub(crate) native: FxHashMap<FileId, Vec<lsp_types::Diagnostic>>,
22 pub(crate) check: HashMap<FileId, Vec<lsp_types::Diagnostic>>, 22 pub(crate) check: FxHashMap<FileId, Vec<lsp_types::Diagnostic>>,
23 pub(crate) check_fixes: CheckFixes, 23 pub(crate) check_fixes: CheckFixes,
24 changes: FxHashSet<FileId>, 24 changes: FxHashSet<FileId>,
25} 25}
diff --git a/docs/dev/README.md b/docs/dev/README.md
index 11dc5261b..6b6824ded 100644
--- a/docs/dev/README.md
+++ b/docs/dev/README.md
@@ -254,6 +254,11 @@ The default name is a lowercased name of the type: `global_state: GlobalState`.
254Avoid ad-hoc acronyms and contractions, but use the ones that exist consistently (`db`, `ctx`, `acc`). 254Avoid ad-hoc acronyms and contractions, but use the ones that exist consistently (`db`, `ctx`, `acc`).
255The default name for "result of the function" local variable is `res`. 255The default name for "result of the function" local variable is `res`.
256 256
257## Collection types
258
259We prefer `rustc_hash::FxHashMap` and `rustc_hash::FxHashSet` instead of the ones in `std::collections`.
260They use a hasher that's slightly faster and using them consistently will reduce code size by some small amount.
261
257## Preconditions 262## Preconditions
258 263
259Function preconditions should generally be expressed in types and provided by the caller (rather than checked by callee): 264Function preconditions should generally be expressed in types and provided by the caller (rather than checked by callee):