Skip to content

Commit b1419bb

Browse files
swap from HashMap to FxHashMap (#232)
1 parent 56cc5b5 commit b1419bb

File tree

9 files changed

+26
-16
lines changed

9 files changed

+26
-16
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dashmap = "6.1"
2424
directories = "6.0"
2525
notify = "8.2"
2626
percent-encoding = "2.3"
27+
rustc-hash = "2.1"
2728
serde = { version = "1.0", features = ["derive"] }
2829
serde_json = "1.0"
2930
thiserror = "2.0"

crates/djls-project/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2021"
77
djls-workspace = { workspace = true }
88

99
anyhow = { workspace = true }
10+
rustc-hash = { workspace = true }
1011
salsa = { workspace = true }
1112
serde = { workspace = true }
1213
serde_json = { workspace = true }

crates/djls-project/src/system.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ pub fn env_var(key: &str) -> Result<String, VarError> {
2828
#[cfg(test)]
2929
pub mod mock {
3030
use std::cell::RefCell;
31-
use std::collections::HashMap;
3231
use std::thread_local;
3332

33+
use rustc_hash::FxHashMap;
34+
3435
use super::*;
3536

3637
thread_local! {
37-
static MOCK_EXEC_RESULTS: RefCell<HashMap<String, Result<PathBuf, WhichError>>> = RefCell::new(HashMap::new());
38-
static MOCK_ENV_RESULTS: RefCell<HashMap<String, Result<String, VarError>>> = RefCell::new(HashMap::new());
38+
static MOCK_EXEC_RESULTS: RefCell<FxHashMap<String, Result<PathBuf, WhichError>>> = RefCell::new(FxHashMap::default());
39+
static MOCK_ENV_RESULTS: RefCell<FxHashMap<String, Result<String, VarError>>> = RefCell::new(FxHashMap::default());
3940
}
4041

4142
pub(super) fn find_executable_mocked(name: &str) -> Result<PathBuf, WhichError> {

crates/djls-semantic/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ djls-conf = { workspace = true }
88
djls-templates = { workspace = true }
99
djls-workspace = { workspace = true }
1010

11+
rustc-hash = { workspace = true }
1112
salsa = { workspace = true }
1213
serde = { workspace = true }
1314
thiserror = { workspace = true }

crates/djls-semantic/src/builtins.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
//! This module defines all the standard Django template tags as compile-time
44
//! constants, avoiding the need for runtime TOML parsing.
55
6-
use std::collections::HashMap;
76
use std::sync::LazyLock;
87

8+
use rustc_hash::FxHashMap;
9+
910
use super::specs::EndTag;
1011
use super::specs::IntermediateTag;
1112
use super::specs::TagArg;
@@ -14,7 +15,7 @@ use super::specs::TagSpecs;
1415

1516
// Static storage for built-in specs - built only once on first access
1617
static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
17-
let mut specs = HashMap::new();
18+
let mut specs = FxHashMap::default();
1819

1920
// Define all Django built-in tags using direct struct construction
2021
let tags = vec![
@@ -380,7 +381,7 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
380381
},
381382
];
382383

383-
// Insert all tags into the HashMap
384+
// Insert all tags into the FxHashMap
384385
for tag in tags {
385386
if let Some(ref name) = tag.name {
386387
specs.insert(name.clone(), tag);

crates/djls-semantic/src/specs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use rustc_hash::FxHashMap;
22

33
pub enum TagType {
44
Opener,
@@ -23,11 +23,11 @@ impl TagType {
2323
}
2424

2525
#[derive(Clone, Debug, Default)]
26-
pub struct TagSpecs(HashMap<String, TagSpec>);
26+
pub struct TagSpecs(FxHashMap<String, TagSpec>);
2727

2828
impl TagSpecs {
2929
#[must_use]
30-
pub fn new(specs: HashMap<String, TagSpec>) -> Self {
30+
pub fn new(specs: FxHashMap<String, TagSpec>) -> Self {
3131
TagSpecs(specs)
3232
}
3333

@@ -122,7 +122,7 @@ impl From<&djls_conf::Settings> for TagSpecs {
122122
let mut specs = crate::builtins::django_builtin_specs();
123123

124124
// Convert and merge user-defined tagspecs
125-
let mut user_specs = HashMap::new();
125+
let mut user_specs = FxHashMap::default();
126126
for tagspec_def in settings.tagspecs() {
127127
// Clone because we're consuming the tagspec_def in the conversion
128128
let tagspec: TagSpec = tagspec_def.clone().into();
@@ -312,7 +312,7 @@ mod tests {
312312

313313
// Helper function to create a small test TagSpecs
314314
fn create_test_specs() -> TagSpecs {
315-
let mut specs = HashMap::new();
315+
let mut specs = FxHashMap::default();
316316

317317
// Add a simple single tag
318318
specs.insert(
@@ -567,7 +567,7 @@ mod tests {
567567
let mut specs1 = create_test_specs();
568568

569569
// Create another TagSpecs with some overlapping and some new tags
570-
let mut specs2_map = HashMap::new();
570+
let mut specs2_map = FxHashMap::default();
571571

572572
// Add a new tag
573573
specs2_map.insert(
@@ -626,7 +626,7 @@ mod tests {
626626
let original_count = specs.iter().count();
627627

628628
// Merge with empty TagSpecs
629-
specs.merge(TagSpecs::new(HashMap::new()));
629+
specs.merge(TagSpecs::new(FxHashMap::default()));
630630

631631
// Should remain unchanged
632632
assert_eq!(specs.iter().count(), original_count);

crates/djls-workspace/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ camino = { workspace = true }
99
dashmap = { workspace = true }
1010
notify = { workspace = true }
1111
percent-encoding = { workspace = true }
12+
rustc-hash = { workspace = true }
1213
salsa = { workspace = true }
1314
tokio = { workspace = true }
1415
tower-lsp-server = { workspace = true }

crates/djls-workspace/src/fs.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
//! This module provides the [`FileSystem`] trait that abstracts file I/O operations.
44
//! This allows the LSP to work with both real files and in-memory overlays.
55
6-
use std::collections::HashMap;
76
use std::io;
87
use std::path::Path;
98
use std::path::PathBuf;
109
use std::sync::Arc;
1110

11+
use rustc_hash::FxHashMap;
12+
1213
use crate::buffers::Buffers;
1314
use crate::paths;
1415

@@ -18,14 +19,14 @@ pub trait FileSystem: Send + Sync {
1819
}
1920

2021
pub struct InMemoryFileSystem {
21-
files: HashMap<PathBuf, String>,
22+
files: FxHashMap<PathBuf, String>,
2223
}
2324

2425
impl InMemoryFileSystem {
2526
#[must_use]
2627
pub fn new() -> Self {
2728
Self {
28-
files: HashMap::new(),
29+
files: FxHashMap::default(),
2930
}
3031
}
3132

0 commit comments

Comments
 (0)