diff --git a/Cargo.lock b/Cargo.lock index a08cb1a1..fc4faa7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2650,6 +2650,7 @@ dependencies = [ "line-index", "log", "rowan", + "rustc-hash 2.1.1", "salsa", "smallvec", "smol_str", @@ -2676,6 +2677,7 @@ dependencies = [ "lazy_static", "line-index", "rowan", + "rustc-hash 2.1.1", "serde", "serde_plain", "squawk-syntax", @@ -2707,6 +2709,7 @@ dependencies = [ "lsp-server", "lsp-types", "rowan", + "rustc-hash 2.1.1", "salsa", "serde", "serde_json", @@ -3663,6 +3666,7 @@ dependencies = [ "quote", "regex", "reqwest", + "rustc-hash 2.1.1", "serde", "serde_json", "ungrammar", diff --git a/Cargo.toml b/Cargo.toml index 3386dce9..bf3e6b08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,6 +69,7 @@ crossbeam-utils = "0.8.21" jod-thread = "0.1.2" libc = "0.2.171" tracing = "0.1.40" +rustc-hash = "2.1.1" # local # we have to make the versions explicit otherwise `cargo publish` won't work @@ -89,6 +90,7 @@ doc_markdown = "deny" manual_let_else = "deny" explicit_iter_loop = "deny" too_many_arguments = "allow" +disallowed_types = "deny" [profile.dev] debug = 0 diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 00000000..29344da5 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,4 @@ +disallowed-types = [ + { path = "std::collections::HashMap", reason = "Use rustc_hash::FxHashMap instead" }, + { path = "std::collections::HashSet", reason = "Use rustc_hash::FxHashSet instead" }, +] diff --git a/crates/squawk_ide/Cargo.toml b/crates/squawk_ide/Cargo.toml index 4532afb9..c3f13eb7 100644 --- a/crates/squawk_ide/Cargo.toml +++ b/crates/squawk_ide/Cargo.toml @@ -28,6 +28,7 @@ la-arena.workspace = true smallvec.workspace = true itertools.workspace = true etcetera.workspace = true +rustc-hash.workspace = true [dev-dependencies] insta.workspace = true diff --git a/crates/squawk_ide/src/folding_ranges.rs b/crates/squawk_ide/src/folding_ranges.rs index 79d43bed..00c4ce45 100644 --- a/crates/squawk_ide/src/folding_ranges.rs +++ b/crates/squawk_ide/src/folding_ranges.rs @@ -27,7 +27,7 @@ // NOTE: pretty much copied as is but simplfied a fair bit. I don't use folding // much so not sure if this is optimal. -use std::collections::HashSet; +use rustc_hash::FxHashSet; use rowan::{Direction, NodeOrToken, TextRange}; use salsa::Database as Db; @@ -60,7 +60,7 @@ pub fn folding_ranges(db: &dyn Db, file: File) -> Vec { let parse = parse(db, file); let mut folds = vec![]; - let mut visited_comments = HashSet::default(); + let mut visited_comments = FxHashSet::default(); for element in parse.tree().syntax().descendants_with_tokens() { match &element { @@ -166,7 +166,7 @@ fn fold_kind(kind: SyntaxKind) -> Option { fn contiguous_range_for_comment( first: ast::Comment, - visited: &mut HashSet, + visited: &mut FxHashSet, ) -> Option { visited.insert(first.clone()); diff --git a/crates/squawk_ide/src/scope.rs b/crates/squawk_ide/src/scope.rs index e04674a6..c7d81a75 100644 --- a/crates/squawk_ide/src/scope.rs +++ b/crates/squawk_ide/src/scope.rs @@ -1,5 +1,5 @@ use la_arena::Idx; -use std::collections::HashMap; +use rustc_hash::FxHashMap; use crate::symbols::{Name, SymbolId}; @@ -9,14 +9,14 @@ pub(crate) type ScopeId = Idx; pub(crate) struct Scope { #[allow(dead_code)] pub(crate) parent: Option, - pub(crate) entries: HashMap>, + pub(crate) entries: FxHashMap>, } impl Scope { pub(crate) fn with_parent(parent: Option) -> Self { Scope { parent, - entries: HashMap::new(), + entries: FxHashMap::default(), } } diff --git a/crates/squawk_linter/Cargo.toml b/crates/squawk_linter/Cargo.toml index 31ddbdaa..269d778a 100644 --- a/crates/squawk_linter/Cargo.toml +++ b/crates/squawk_linter/Cargo.toml @@ -24,7 +24,7 @@ enum-iterator.workspace = true line-index.workspace = true serde_plain.workspace = true annotate-snippets.workspace = true - +rustc-hash.workspace = true [lints] workspace = true diff --git a/crates/squawk_linter/src/ignore.rs b/crates/squawk_linter/src/ignore.rs index 01ce5c2b..9e7cffc4 100644 --- a/crates/squawk_linter/src/ignore.rs +++ b/crates/squawk_linter/src/ignore.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use rustc_hash::FxHashSet; use rowan::{NodeOrToken, TextRange, TextSize}; use squawk_syntax::{SyntaxKind, SyntaxNode, SyntaxToken}; @@ -14,7 +14,7 @@ pub enum IgnoreKind { #[derive(Debug)] pub struct Ignore { pub range: TextRange, - pub violation_names: HashSet, + pub violation_names: FxHashSet, pub ignore_all: bool, pub kind: IgnoreKind, } @@ -79,7 +79,7 @@ pub(crate) fn find_ignores(ctx: &mut Linter, file: &SyntaxNode) { if token.kind() == SyntaxKind::COMMENT => { if let Some((rule_names, range, kind)) = ignore_rule_info(&token) { - let mut set = HashSet::new(); + let mut set = FxHashSet::default(); let mut offset = 0usize; // We have a specific check instead of going off of empty // rules in case we have invalid rule names specified in the diff --git a/crates/squawk_linter/src/ignore_index.rs b/crates/squawk_linter/src/ignore_index.rs index dc64a6aa..41562d9a 100644 --- a/crates/squawk_linter/src/ignore_index.rs +++ b/crates/squawk_linter/src/ignore_index.rs @@ -1,7 +1,6 @@ -use std::{ - collections::{HashMap, HashSet}, - fmt, -}; +use std::fmt; + +use rustc_hash::{FxHashMap, FxHashSet}; use line_index::LineIndex; use rowan::TextRange; @@ -9,8 +8,8 @@ use rowan::TextRange; use crate::{Ignore, Rule, ignore::IgnoreKind}; pub(crate) struct IgnoreIndex { - line_to_ignored: HashMap>, - file_ignored: HashSet, + line_to_ignored: FxHashMap>, + file_ignored: FxHashSet, ignore_all: bool, line_index: LineIndex, } @@ -32,8 +31,8 @@ impl fmt::Debug for IgnoreIndex { impl IgnoreIndex { pub(crate) fn new(text: &str, ignores: &[Ignore]) -> Self { let line_index = LineIndex::new(text); - let mut line_to_ignored: HashMap> = HashMap::new(); - let mut file_ignored: HashSet = HashSet::new(); + let mut line_to_ignored: FxHashMap> = FxHashMap::default(); + let mut file_ignored: FxHashSet = FxHashSet::default(); let mut ignore_all = false; for ignore in ignores { match ignore.kind { diff --git a/crates/squawk_linter/src/lib.rs b/crates/squawk_linter/src/lib.rs index e72654b6..633a7dc4 100644 --- a/crates/squawk_linter/src/lib.rs +++ b/crates/squawk_linter/src/lib.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use rustc_hash::{FxBuildHasher, FxHashSet}; use std::fmt; use enum_iterator::Sequence; @@ -317,7 +317,7 @@ pub struct LinterSettings { pub struct Linter { errors: Vec, ignores: Vec, - pub rules: HashSet, + pub rules: FxHashSet, pub settings: LinterSettings, } @@ -452,13 +452,13 @@ impl Linter { } pub fn with_all_rules() -> Self { - let rules = all::().collect::>(); + let rules = all::().collect::>(); Linter::from(rules) } pub fn without_rules(exclude: &[Rule]) -> Self { - let all_rules = all::().collect::>(); - let mut exclude_set = HashSet::with_capacity(exclude.len()); + let all_rules = all::().collect::>(); + let mut exclude_set = FxHashSet::with_capacity_and_hasher(exclude.len(), FxBuildHasher); for e in exclude { exclude_set.insert(e); } @@ -466,16 +466,16 @@ impl Linter { let rules = all_rules .into_iter() .filter(|x| !exclude_set.contains(x)) - .collect::>(); + .collect::>(); Linter::from(rules) } - pub fn from(rules: impl Into>) -> Self { + pub fn from(rules: impl IntoIterator) -> Self { Self { errors: vec![], ignores: vec![], - rules: rules.into(), + rules: rules.into_iter().collect(), settings: Default::default(), } } diff --git a/crates/squawk_linter/src/rules/adding_field_with_default.rs b/crates/squawk_linter/src/rules/adding_field_with_default.rs index 69c73af4..aeb1288e 100644 --- a/crates/squawk_linter/src/rules/adding_field_with_default.rs +++ b/crates/squawk_linter/src/rules/adding_field_with_default.rs @@ -1,5 +1,5 @@ use lazy_static::lazy_static; -use std::collections::HashSet; +use rustc_hash::FxHashSet; use squawk_syntax::ast::AstNode; use squawk_syntax::{Parse, SourceFile, SyntaxKind}; @@ -8,7 +8,7 @@ use squawk_syntax::{ast, identifier::Identifier}; use crate::{Linter, Rule, Version, Violation}; lazy_static! { - static ref NON_VOLATILE_FUNCS: HashSet = { + static ref NON_VOLATILE_FUNCS: FxHashSet = { NON_VOLATILE_BUILT_IN_FUNCTIONS .split('\n') .map(|x| x.trim()) diff --git a/crates/squawk_linter/src/rules/adding_not_null_field.rs b/crates/squawk_linter/src/rules/adding_not_null_field.rs index dc3323a2..38307f75 100644 --- a/crates/squawk_linter/src/rules/adding_not_null_field.rs +++ b/crates/squawk_linter/src/rules/adding_not_null_field.rs @@ -1,4 +1,4 @@ -use std::collections::{HashMap, HashSet}; +use rustc_hash::{FxHashMap, FxHashSet}; use squawk_syntax::{ Parse, SourceFile, @@ -49,11 +49,12 @@ pub(crate) fn adding_not_null_field(ctx: &mut Linter, parse: &Parse) let is_pg12_plus = ctx.settings.pg_version >= Version::new(12, None, None); - let mut not_null_constraints: HashMap = HashMap::new(); - let mut validated_not_null_columns: HashSet = HashSet::new(); + let mut not_null_constraints: FxHashMap = FxHashMap::default(); + let mut validated_not_null_columns: FxHashSet = FxHashSet::default(); // Tables where VALIDATE CONSTRAINT was seen without a matching ADD CONSTRAINT // in the same file (cross-migration pattern). - let mut tables_with_external_validated_constraints: HashSet = HashSet::new(); + let mut tables_with_external_validated_constraints: FxHashSet = + FxHashSet::default(); for stmt in file.stmts() { if let ast::Stmt::AlterTable(alter_table) = stmt { diff --git a/crates/squawk_linter/src/rules/ban_char_field.rs b/crates/squawk_linter/src/rules/ban_char_field.rs index 12b28b5d..02fc8768 100644 --- a/crates/squawk_linter/src/rules/ban_char_field.rs +++ b/crates/squawk_linter/src/rules/ban_char_field.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use rustc_hash::FxHashSet; use rowan::TextRange; use squawk_syntax::{ @@ -13,11 +13,13 @@ use crate::{Edit, Fix, Linter, Rule, Violation}; use lazy_static::lazy_static; lazy_static! { - static ref CHAR_TYPES: HashSet = HashSet::from([ + static ref CHAR_TYPES: FxHashSet = [ Identifier::new("char"), Identifier::new("character"), Identifier::new("bpchar"), - ]); + ] + .into_iter() + .collect(); } fn is_char_type(x: TokenText<'_>) -> bool { diff --git a/crates/squawk_linter/src/rules/constraint_missing_not_valid.rs b/crates/squawk_linter/src/rules/constraint_missing_not_valid.rs index de634466..b297d7e0 100644 --- a/crates/squawk_linter/src/rules/constraint_missing_not_valid.rs +++ b/crates/squawk_linter/src/rules/constraint_missing_not_valid.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use rustc_hash::FxHashSet; use squawk_syntax::{ Parse, SourceFile, @@ -11,8 +11,8 @@ use crate::{Linter, Rule, Violation}; pub fn tables_created_in_transaction( assume_in_transaction: bool, file: &ast::SourceFile, -) -> HashSet { - let mut created_table_names = HashSet::new(); +) -> FxHashSet { + let mut created_table_names = FxHashSet::default(); let mut inside_transaction = assume_in_transaction; for stmt in file.stmts() { match stmt { @@ -44,7 +44,7 @@ fn not_valid_validate_in_transaction( file: &ast::SourceFile, ) { let mut inside_transaction = assume_in_transaction; - let mut not_valid_names: HashSet = HashSet::new(); + let mut not_valid_names: FxHashSet = FxHashSet::default(); for stmt in file.stmts() { match stmt { ast::Stmt::AlterTable(alter_table) => { diff --git a/crates/squawk_linter/src/rules/prefer_bigint_over_int.rs b/crates/squawk_linter/src/rules/prefer_bigint_over_int.rs index 4582e02b..e1bcfa32 100644 --- a/crates/squawk_linter/src/rules/prefer_bigint_over_int.rs +++ b/crates/squawk_linter/src/rules/prefer_bigint_over_int.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use rustc_hash::FxHashSet; use squawk_syntax::ast::AstNode; use squawk_syntax::{Parse, SourceFile, ast, identifier::Identifier}; @@ -11,13 +11,15 @@ use crate::visitors::is_not_valid_int_type; use lazy_static::lazy_static; lazy_static! { - static ref INT_TYPES: HashSet = HashSet::from([ + static ref INT_TYPES: FxHashSet = [ Identifier::new("int"), Identifier::new("integer"), Identifier::new("int4"), Identifier::new("serial"), Identifier::new("serial4"), - ]); + ] + .into_iter() + .collect(); } fn int_to_bigint_replacement(int_type: &str) -> &'static str { diff --git a/crates/squawk_linter/src/rules/prefer_bigint_over_smallint.rs b/crates/squawk_linter/src/rules/prefer_bigint_over_smallint.rs index d4bc6dcc..4f88cac9 100644 --- a/crates/squawk_linter/src/rules/prefer_bigint_over_smallint.rs +++ b/crates/squawk_linter/src/rules/prefer_bigint_over_smallint.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use rustc_hash::FxHashSet; use squawk_syntax::ast::AstNode; use squawk_syntax::{Parse, SourceFile, ast, identifier::Identifier}; @@ -11,12 +11,14 @@ use crate::visitors::is_not_valid_int_type; use lazy_static::lazy_static; lazy_static! { - static ref SMALL_INT_TYPES: HashSet = HashSet::from([ + static ref SMALL_INT_TYPES: FxHashSet = [ Identifier::new("smallint"), Identifier::new("int2"), Identifier::new("smallserial"), Identifier::new("serial2"), - ]); + ] + .into_iter() + .collect(); } fn smallint_to_bigint(smallint_type: &str) -> &'static str { diff --git a/crates/squawk_linter/src/rules/prefer_identity.rs b/crates/squawk_linter/src/rules/prefer_identity.rs index ef5bd76a..868902ba 100644 --- a/crates/squawk_linter/src/rules/prefer_identity.rs +++ b/crates/squawk_linter/src/rules/prefer_identity.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use rustc_hash::FxHashSet; use squawk_syntax::{ Parse, SourceFile, @@ -13,14 +13,16 @@ use lazy_static::lazy_static; use crate::visitors::{check_not_allowed_types, is_not_valid_int_type}; lazy_static! { - static ref SERIAL_TYPES: HashSet = HashSet::from([ + static ref SERIAL_TYPES: FxHashSet = [ Identifier::new("serial"), Identifier::new("serial2"), Identifier::new("serial4"), Identifier::new("serial8"), Identifier::new("smallserial"), Identifier::new("bigserial"), - ]); + ] + .into_iter() + .collect(); } fn replace_serial(serial_type: &str) -> &'static str { diff --git a/crates/squawk_linter/src/rules/prefer_robust_stmts.rs b/crates/squawk_linter/src/rules/prefer_robust_stmts.rs index 7233af00..ac816b37 100644 --- a/crates/squawk_linter/src/rules/prefer_robust_stmts.rs +++ b/crates/squawk_linter/src/rules/prefer_robust_stmts.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use rustc_hash::FxHashMap; use squawk_syntax::{ Parse, SourceFile, @@ -17,7 +17,7 @@ enum Constraint { pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse) { let file = parse.tree(); let mut inside_transaction = ctx.settings.assume_in_transaction; - let mut constraint_names: HashMap = HashMap::new(); + let mut constraint_names: FxHashMap = FxHashMap::default(); enum ActionErrorMessage { IfExists, diff --git a/crates/squawk_linter/src/rules/prefer_text_field.rs b/crates/squawk_linter/src/rules/prefer_text_field.rs index ea4547f0..ec4d6c42 100644 --- a/crates/squawk_linter/src/rules/prefer_text_field.rs +++ b/crates/squawk_linter/src/rules/prefer_text_field.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use rustc_hash::FxHashSet; use squawk_syntax::{ Parse, SourceFile, @@ -13,7 +13,7 @@ use crate::visitors::check_not_allowed_types; use lazy_static::lazy_static; lazy_static! { - static ref VARCHAR_TYPE_NAMES: HashSet<&'static str> = HashSet::from(["varchar"]); + static ref VARCHAR_TYPE_NAMES: FxHashSet<&'static str> = ["varchar"].into_iter().collect(); } fn is_not_allowed_varchar(ty: &ast::Type) -> bool { diff --git a/crates/squawk_linter/src/visitors.rs b/crates/squawk_linter/src/visitors.rs index 11e337d9..d14976dd 100644 --- a/crates/squawk_linter/src/visitors.rs +++ b/crates/squawk_linter/src/visitors.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use rustc_hash::FxHashSet; use squawk_syntax::{ast, identifier::Identifier}; @@ -6,7 +6,7 @@ use crate::Linter; pub(crate) fn is_not_valid_int_type( ty: &ast::Type, - invalid_type_names: &HashSet, + invalid_type_names: &FxHashSet, ) -> bool { match ty { ast::Type::ArrayType(array_type) => { diff --git a/crates/squawk_server/Cargo.toml b/crates/squawk_server/Cargo.toml index 1b869e56..f3ded112 100644 --- a/crates/squawk_server/Cargo.toml +++ b/crates/squawk_server/Cargo.toml @@ -30,6 +30,7 @@ squawk-syntax.workspace = true line-index.workspace = true insta.workspace = true etcetera.workspace = true +rustc-hash.workspace = true [lints] workspace = true diff --git a/crates/squawk_server/src/handlers/code_action.rs b/crates/squawk_server/src/handlers/code_action.rs index 9e43e9a7..9c247bbc 100644 --- a/crates/squawk_server/src/handlers/code_action.rs +++ b/crates/squawk_server/src/handlers/code_action.rs @@ -3,9 +3,9 @@ use lsp_types::{ CodeAction, CodeActionKind, CodeActionOrCommand, CodeActionParams, CodeActionResponse, Command, WorkspaceEdit, }; +use rustc_hash::FxHashMap; use squawk_ide::code_actions::code_actions; use squawk_ide::db::line_index; -use std::collections::HashMap; use crate::diagnostic::{AssociatedDiagnosticData, DIAGNOSTIC_NAME}; use crate::lsp_utils; @@ -57,9 +57,9 @@ pub(crate) fn handle_code_action( diagnostics: Some(vec![diagnostic.clone()]), edit: Some(WorkspaceEdit { changes: Some({ - let mut changes = HashMap::new(); + let mut changes = FxHashMap::default(); changes.insert(uri.clone(), vec![ignore_line_edit]); - changes + changes.into_iter().collect() }), ..Default::default() }), @@ -77,9 +77,9 @@ pub(crate) fn handle_code_action( diagnostics: Some(vec![diagnostic.clone()]), edit: Some(WorkspaceEdit { changes: Some({ - let mut changes = HashMap::new(); + let mut changes = FxHashMap::default(); changes.insert(uri.clone(), vec![ignore_file_edit]); - changes + changes.into_iter().collect() }), ..Default::default() }), @@ -117,9 +117,9 @@ pub(crate) fn handle_code_action( diagnostics: Some(vec![diagnostic.clone()]), edit: Some(WorkspaceEdit { changes: Some({ - let mut changes = HashMap::new(); + let mut changes = FxHashMap::default(); changes.insert(uri.clone(), associated_data.edits); - changes + changes.into_iter().collect() }), ..Default::default() }), diff --git a/crates/squawk_server/src/handlers/notifications.rs b/crates/squawk_server/src/handlers/notifications.rs index 59bff095..515268a7 100644 --- a/crates/squawk_server/src/handlers/notifications.rs +++ b/crates/squawk_server/src/handlers/notifications.rs @@ -7,7 +7,7 @@ use lsp_types::{ }; use crate::lsp_utils; -use crate::system::{Document, System}; +use crate::system::System; pub(crate) fn handle_did_open( _connection: &Connection, @@ -17,7 +17,7 @@ pub(crate) fn handle_did_open( let uri = params.text_document.uri; let content = params.text_document.text; - system.set(uri, Document { content }); + system.set(uri, content); Ok(()) } @@ -35,12 +35,7 @@ pub(crate) fn handle_did_change( let updated_content = lsp_utils::apply_incremental_changes(content, params.content_changes); - system.set( - uri, - Document { - content: updated_content, - }, - ); + system.set(uri, updated_content); Ok(()) } diff --git a/crates/squawk_server/src/lsp_utils.rs b/crates/squawk_server/src/lsp_utils.rs index 675a4f06..a677ff91 100644 --- a/crates/squawk_server/src/lsp_utils.rs +++ b/crates/squawk_server/src/lsp_utils.rs @@ -1,4 +1,6 @@ -use std::{collections::HashMap, ops::Range}; +use std::ops::Range; + +use rustc_hash::FxHashMap; use ::line_index::{LineIndex, TextRange, TextSize}; use log::warn; @@ -62,7 +64,7 @@ pub(crate) fn code_action( diagnostics: None, edit: Some(WorkspaceEdit { changes: Some({ - let mut changes = HashMap::new(); + let mut changes = FxHashMap::default(); let edits = action .edits .into_iter() @@ -72,7 +74,7 @@ pub(crate) fn code_action( }) .collect(); changes.insert(uri, edits); - changes + changes.into_iter().collect() }), ..Default::default() }), diff --git a/crates/squawk_server/src/system.rs b/crates/squawk_server/src/system.rs index 3a5e43f6..25e55657 100644 --- a/crates/squawk_server/src/system.rs +++ b/crates/squawk_server/src/system.rs @@ -1,29 +1,25 @@ use lsp_types::Url; +use rustc_hash::FxHashMap; use salsa::Setter; use squawk_ide::db::{Database, File}; -use std::collections::HashMap; - -pub(crate) struct Document { - pub(crate) content: String, -} pub(crate) trait System { fn db(&self) -> &Database; fn file(&self, uri: &Url) -> Option; - fn set(&mut self, uri: Url, doc: Document); + fn set(&mut self, uri: Url, content: String); fn remove(&mut self, uri: &Url); } pub(super) struct GlobalState { pub db: Database, - files: HashMap, + files: FxHashMap, } impl GlobalState { pub(super) fn new() -> Self { Self { db: Database::default(), - files: HashMap::new(), + files: FxHashMap::default(), } } } @@ -37,11 +33,11 @@ impl System for GlobalState { self.files.get(uri).copied() } - fn set(&mut self, uri: Url, doc: Document) { + fn set(&mut self, uri: Url, content: String) { if let Some(file) = self.files.get(&uri).copied() { - file.set_content(&mut self.db).to(doc.content.into()); + file.set_content(&mut self.db).to(content.into()); } else { - let file = File::new(&self.db, doc.content.into()); + let file = File::new(&self.db, content.into()); self.files.insert(uri, file); } } diff --git a/crates/xtask/Cargo.toml b/crates/xtask/Cargo.toml index 3254d595..1ecfb0b3 100644 --- a/crates/xtask/Cargo.toml +++ b/crates/xtask/Cargo.toml @@ -22,6 +22,7 @@ quote.workspace = true xshell.workspace = true proc-macro2.workspace = true regex.workspace = true +rustc-hash.workspace = true [lints] workspace = true diff --git a/crates/xtask/src/codegen.rs b/crates/xtask/src/codegen.rs index b951649c..112ebe6a 100644 --- a/crates/xtask/src/codegen.rs +++ b/crates/xtask/src/codegen.rs @@ -23,7 +23,7 @@ // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use std::collections::HashSet; +use rustc_hash::FxHashSet; use anyhow::{Context, Result}; use convert_case::{Case, Casing}; @@ -801,7 +801,7 @@ fn generate_nodes(nodes: &[AstNodeSrc], enums: &[AstEnumSrc]) -> String { }) .unzip(); - let enum_nodes = enums.iter().map(|x| &x.name).collect::>(); + let enum_nodes = enums.iter().map(|x| &x.name).collect::>(); let (enums, enums_boilierplate_impls): (Vec<_>, Vec<_>) = enums .iter() diff --git a/crates/xtask/src/keywords.rs b/crates/xtask/src/keywords.rs index 62d1dbf5..48c37ad1 100644 --- a/crates/xtask/src/keywords.rs +++ b/crates/xtask/src/keywords.rs @@ -1,7 +1,7 @@ use crate::path::project_root; use anyhow::{Context, Ok, Result}; use enum_iterator::{Sequence, all}; -use std::collections::{HashMap, HashSet}; +use rustc_hash::{FxHashMap, FxHashSet}; struct KeywordMeta { pub(crate) category: KeywordCategory, @@ -74,11 +74,11 @@ fn keyword_allowed(cat: KeywordCategory, kw_type: KWType) -> bool { } } -fn parse_header() -> Result> { +fn parse_header() -> Result> { let kwlist_file = project_root().join("postgres/kwlist.h"); let data = std::fs::read_to_string(kwlist_file).context("Failed to read kwlist.h")?; - let mut keywords = HashMap::new(); + let mut keywords = FxHashMap::default(); for line in data.lines() { if line.starts_with("PG_KEYWORD") { @@ -158,8 +158,8 @@ pub(crate) fn keyword_kinds() -> Result { .collect::>(); all_keywords.sort(); - let mut col_table_tokens = HashSet::new(); - let mut type_tokens = HashSet::new(); + let mut col_table_tokens = FxHashSet::default(); + let mut type_tokens = FxHashSet::default(); for (key, meta) in &keywords { for variant in all::() { match variant {