Skip to content

Commit

Permalink
Switch some HashMaps to FxHashMaps
Browse files Browse the repository at this point in the history
FxHashMap has a faster hashing algorithm,
at the expense of not being resistent to DOS
attacks.
  • Loading branch information
Colecf committed Jan 22, 2024
1 parent 9ccb5bf commit 4dfa366
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions src/eval.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -123,7 +124,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) {
Expand Down
4 changes: 3 additions & 1 deletion src/graph.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! The build graph, a graph between files and commands.

use rustc_hash::FxHashMap;

use crate::{
densemap::{self, DenseMap},
hash::BuildHash,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4dfa366

Please sign in to comment.