summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCole Faust <colecfaust@gmail.com>2024-01-21 21:26:15 -0800
committerEvan Martin <evan.martin@gmail.com>2024-01-25 00:30:16 -0800
commit668d9ab5cdbd493a8af356078066423487ac81e2 (patch)
tree87479e0396101ba6de2a8a4eda49089574322257
parent66b02a579a0a857dbac5688e24cdb2f64f311b01 (diff)
downloadn2-668d9ab5cdbd493a8af356078066423487ac81e2.tar.gz
Switch some HashMaps to FxHashMaps
FxHashMap has a faster hashing algorithm, at the expense of not being resistent to DOS attacks.
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml1
-rw-r--r--src/eval.rs5
-rw-r--r--src/graph.rs4
4 files changed, 14 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a85fb04..19c25c1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -393,6 +393,7 @@ dependencies = [
"filetime",
"jemallocator",
"libc",
+ "rustc-hash",
"tempfile",
"windows-sys 0.48.0",
]
@@ -532,6 +533,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
+name = "rustc-hash"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
+
+[[package]]
name = "rustix"
version = "0.37.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 43e21af..b91b120 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,6 +18,7 @@ description = "a ninja compatible build system"
anyhow = "1.0"
argh = "0.1.10"
libc = "0.2"
+rustc-hash = "1.1.0"
[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.48"
diff --git a/src/eval.rs b/src/eval.rs
index 4b711c5..d737bfe 100644
--- a/src/eval.rs
+++ b/src/eval.rs
@@ -1,10 +1,11 @@
//! Represents parsed Ninja strings with embedded variable references, e.g.
//! `c++ $in -o $out`, and mechanisms for expanding those into plain strings.
+use rustc_hash::FxHashMap;
+
use crate::smallmap::SmallMap;
use std::borrow::Borrow;
use std::borrow::Cow;
-use std::collections::HashMap;
/// An environment providing a mapping of variable name to variable value.
/// This represents one "frame" of evaluation context, a given EvalString may
@@ -121,7 +122,7 @@ impl EvalString<&str> {
/// A single scope's worth of variable definitions.
#[derive(Debug, Default)]
-pub struct Vars<'text>(HashMap<&'text str, String>);
+pub struct Vars<'text>(FxHashMap<&'text str, String>);
impl<'text> Vars<'text> {
pub fn insert(&mut self, key: &'text str, val: String) {
diff --git a/src/graph.rs b/src/graph.rs
index f15c35a..d6b1a38 100644
--- a/src/graph.rs
+++ b/src/graph.rs
@@ -1,5 +1,7 @@
//! The build graph, a graph between files and commands.
+use rustc_hash::FxHashMap;
+
use crate::{
densemap::{self, DenseMap},
hash::BuildHash,
@@ -258,7 +260,7 @@ pub struct Graph {
#[derive(Default)]
pub struct GraphFiles {
pub by_id: DenseMap<FileId, File>,
- by_name: HashMap<String, FileId>,
+ by_name: FxHashMap<String, FileId>,
}
impl Graph {