diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-06-29 16:39:51 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-29 16:39:51 +0100 |
commit | 4da0a78c4e65e4abc5ca4ae1ed879e4e86737c9e (patch) | |
tree | 2bbefd6c7b7ad012a1e26f066ed87d716a484387 | |
parent | 32ee06032785ea1792144f7263cbce93a4de467b (diff) | |
parent | 95d67ec40174ec1c344ab39eee414d7a41a36af0 (diff) |
Merge #5126
5126: Use more of FxHash* r=matklad a=lnicola
```
-rwxr-xr-x 1 me me 37917528 Jun 29 17:26 /home/me/.cargo/bin/rust-analyzer
-rwxr-xr-x 1 me me 37904056 Jun 29 18:14 /home/me/.cargo/bin/rust-analyzer
```
Saved 13.5 KB there :-).
Co-authored-by: Laurențiu Nicola <[email protected]>
-rw-r--r-- | crates/ra_assists/src/handlers/reorder_fields.rs | 6 | ||||
-rw-r--r-- | crates/ra_ssr/src/parsing.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_stats.rs | 10 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/diagnostics.rs | 7 | ||||
-rw-r--r-- | crates/rust-analyzer/src/diagnostics.rs | 10 | ||||
-rw-r--r-- | docs/dev/README.md | 5 |
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 @@ | |||
1 | use std::collections::HashMap; | 1 | use itertools::Itertools; |
2 | use rustc_hash::FxHashMap; | ||
2 | 3 | ||
3 | use hir::{Adt, ModuleDef, PathResolution, Semantics, Struct}; | 4 | use hir::{Adt, ModuleDef, PathResolution, Semantics, Struct}; |
4 | use itertools::Itertools; | ||
5 | use ra_ide_db::RootDatabase; | 5 | use ra_ide_db::RootDatabase; |
6 | use ra_syntax::{algo, ast, match_ast, AstNode, SyntaxKind, SyntaxKind::*, SyntaxNode}; | 6 | use 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 | ||
90 | fn compute_fields_ranks(path: &ast::Path, ctx: &AssistContext) -> Option<HashMap<String, usize>> { | 90 | fn 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. |
167 | fn validate_rule(rule: &SsrRule) -> Result<(), SsrError> { | 167 | fn 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 | ||
4 | use std::{collections::HashSet, path::Path, time::Instant}; | 4 | use std::{path::Path, time::Instant}; |
5 | |||
6 | use itertools::Itertools; | ||
7 | use rand::{seq::SliceRandom, thread_rng}; | ||
8 | use rustc_hash::FxHashSet; | ||
5 | 9 | ||
6 | use hir::{ | 10 | use hir::{ |
7 | db::{AstDatabase, DefDatabase, HirDatabase}, | 11 | db::{AstDatabase, DefDatabase, HirDatabase}, |
@@ -9,10 +13,8 @@ use hir::{ | |||
9 | }; | 13 | }; |
10 | use hir_def::FunctionId; | 14 | use hir_def::FunctionId; |
11 | use hir_ty::{Ty, TypeWalk}; | 15 | use hir_ty::{Ty, TypeWalk}; |
12 | use itertools::Itertools; | ||
13 | use ra_db::SourceDatabaseExt; | 16 | use ra_db::SourceDatabaseExt; |
14 | use ra_syntax::AstNode; | 17 | use ra_syntax::AstNode; |
15 | use rand::{seq::SliceRandom, thread_rng}; | ||
16 | use stdx::format_to; | 18 | use stdx::format_to; |
17 | 19 | ||
18 | use crate::cli::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity}; | 20 | use 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 | ||
4 | use std::path::Path; | ||
5 | |||
4 | use anyhow::anyhow; | 6 | use anyhow::anyhow; |
7 | use rustc_hash::FxHashSet; | ||
8 | |||
5 | use hir::Crate; | 9 | use hir::Crate; |
6 | use ra_db::SourceDatabaseExt; | 10 | use ra_db::SourceDatabaseExt; |
7 | use ra_ide::Severity; | 11 | use ra_ide::Severity; |
8 | use std::{collections::HashSet, path::Path}; | ||
9 | 12 | ||
10 | use crate::cli::{load_cargo::load_cargo, Result}; | 13 | use 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. |
2 | pub(crate) mod to_proto; | 2 | pub(crate) mod to_proto; |
3 | 3 | ||
4 | use std::{collections::HashMap, mem, sync::Arc}; | 4 | use std::{mem, sync::Arc}; |
5 | 5 | ||
6 | use ra_ide::FileId; | 6 | use ra_ide::FileId; |
7 | use rustc_hash::FxHashSet; | 7 | use rustc_hash::{FxHashMap, FxHashSet}; |
8 | 8 | ||
9 | use crate::lsp_ext; | 9 | use crate::lsp_ext; |
10 | 10 | ||
11 | pub(crate) type CheckFixes = Arc<HashMap<FileId, Vec<Fix>>>; | 11 | pub(crate) type CheckFixes = Arc<FxHashMap<FileId, Vec<Fix>>>; |
12 | 12 | ||
13 | #[derive(Debug, Default, Clone)] | 13 | #[derive(Debug, Default, Clone)] |
14 | pub struct DiagnosticsConfig { | 14 | pub struct DiagnosticsConfig { |
@@ -18,8 +18,8 @@ pub struct DiagnosticsConfig { | |||
18 | 18 | ||
19 | #[derive(Debug, Default, Clone)] | 19 | #[derive(Debug, Default, Clone)] |
20 | pub(crate) struct DiagnosticCollection { | 20 | pub(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`. | |||
254 | Avoid ad-hoc acronyms and contractions, but use the ones that exist consistently (`db`, `ctx`, `acc`). | 254 | Avoid ad-hoc acronyms and contractions, but use the ones that exist consistently (`db`, `ctx`, `acc`). |
255 | The default name for "result of the function" local variable is `res`. | 255 | The default name for "result of the function" local variable is `res`. |
256 | 256 | ||
257 | ## Collection types | ||
258 | |||
259 | We prefer `rustc_hash::FxHashMap` and `rustc_hash::FxHashSet` instead of the ones in `std::collections`. | ||
260 | They 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 | ||
259 | Function preconditions should generally be expressed in types and provided by the caller (rather than checked by callee): | 264 | Function preconditions should generally be expressed in types and provided by the caller (rather than checked by callee): |