Skip to content

Commit

Permalink
Replace std HashMap with ahash one, which is faster
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenperera committed Mar 4, 2024
1 parent fe487da commit 3287475
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 73 deletions.
121 changes: 55 additions & 66 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ aho-corasick = "1.0"
regex = "1.9"

# logging
env_logger = "0.10"
env_logger = "0.11"
log = "0.4"

# faster hashmap
ahash = "0.8"

# parallel
rayon = "1.5"

Expand Down
2 changes: 1 addition & 1 deletion src/defaults.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ahash::AHashMap as HashMap;
use once_cell::sync::Lazy;
use regex::Regex;
use std::collections::HashMap;

pub static RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r#"\b(?:class(?:Name)*\s*=\s*["'])([_a-zA-Z0-9\.\s\-:\[\]/]+)["']"#).unwrap()
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ pub mod parser;
pub mod sorter;
pub mod tls;

use ahash::AHashSet as HashSet;
use clap::Parser;
use eyre::Result;
use indoc::indoc;
use once_cell::sync::Lazy;
use options::{Options, WriteMode};
use rayon::prelude::*;
use std::collections::HashSet;
use std::fs;
use std::path::Path;
use std::path::PathBuf;
Expand Down
5 changes: 3 additions & 2 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use ignore::WalkBuilder;
use itertools::Itertools;
use regex::Regex;
use serde::Deserialize;
use std::collections::HashMap;
use std::collections::HashSet;
use std::fs;
use std::io::Read;
use std::path::{Path, PathBuf};
use std::str::FromStr;

use ahash::AHashMap as HashMap;
use ahash::AHashSet as HashSet;

use crate::parser;
use crate::Cli;

Expand Down
4 changes: 3 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
collections::{hash_map::Entry, HashMap},
collections::hash_map::Entry,
fs::File,
io::{BufRead, BufReader, Read},
};
Expand All @@ -8,6 +8,8 @@ use eyre::Result;
use once_cell::sync::Lazy;
use regex::Regex;

use ahash::AHashMap as HashMap;

static PARSER_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"^(\.[^\s]+)[ ]").unwrap());

pub fn parse_classes_from_file(css_file: File) -> Result<HashMap<String, usize>> {
Expand Down
4 changes: 3 additions & 1 deletion src/sorter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::{borrow::Cow, collections::HashMap};
use std::borrow::Cow;

use ahash::AHashMap as HashMap;

use aho_corasick::{Anchored, Input};
use itertools::Itertools;
Expand Down

0 comments on commit 3287475

Please sign in to comment.