From 16dab537309593d6b20a5fc6626a58275c6f0fc0 Mon Sep 17 00:00:00 2001 From: underfin Date: Fri, 15 Mar 2024 18:30:37 +0800 Subject: [PATCH] perf: using FxHashMap instead of HashMap (#83) --- Cargo.toml | 1 + src/builder.rs | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c242091..b955431 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ scroll = { version = "0.10.1", features = ["derive"], optional = true } data-encoding = "2.3.3" debugid = {version = "0.8.0", features = ["serde"] } base64-simd = { version = "0.7" } +rustc-hash = "1.1.0" [build-dependencies] rustc_version = "0.2.3" diff --git a/src/builder.rs b/src/builder.rs index b9a4791..bf0e005 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1,6 +1,5 @@ #![cfg_attr(not(any(unix, windows, target_os = "redox")), allow(unused_imports))] -use std::collections::HashMap; use std::convert::AsRef; use std::env; use std::fs; @@ -8,6 +7,7 @@ use std::io::Read; use std::path::{Path, PathBuf}; use debugid::DebugId; +use rustc_hash::FxHashMap; use url::Url; use crate::errors::Result; @@ -20,10 +20,10 @@ use crate::types::{RawToken, SourceMap, Token}; /// type can help. pub struct SourceMapBuilder { file: Option, - name_map: HashMap, + name_map: FxHashMap, names: Vec, tokens: Vec, - source_map: HashMap, + source_map: FxHashMap, source_root: Option, sources: Vec, source_contents: Vec>, @@ -53,10 +53,10 @@ impl SourceMapBuilder { pub fn new(file: Option<&str>) -> SourceMapBuilder { SourceMapBuilder { file: file.map(str::to_owned), - name_map: HashMap::new(), + name_map: FxHashMap::default(), names: vec![], tokens: vec![], - source_map: HashMap::new(), + source_map: FxHashMap::default(), source_root: None, sources: vec![], source_contents: vec![],