Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/filepatterns.rs @ 43826:5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Rust's default hashing is slow, because it is meant for preventing collision
attacks.
For all of the current Rust code, we don't care about those attacks, because
if an person with bad intentions has write access to your repo, you have other
issues.
I've chosen to use the TwoXHash crate because it was made by a reputable member
of the Rust community and has very good benchmarks.
For now it does not seem to improve performance by much for the current code,
but it's something else to not worry about when benchmarking code: in a
previous experiment with copytracing in Rust, it accounted for more than 10%
of the time of the entire script.
Differential Revision: https://phab.mercurial-scm.org/D7116
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 14 Oct 2019 13:57:30 +0200 |
parents | 7a01778bc7b7 |
children | d42eea9a0494 |
comparison
equal
deleted
inserted
replaced
43825:8f26dd09aa78 | 43826:5ac243a92e37 |
---|---|
5 // This software may be used and distributed according to the terms of the | 5 // This software may be used and distributed according to the terms of the |
6 // GNU General Public License version 2 or any later version. | 6 // GNU General Public License version 2 or any later version. |
7 | 7 |
8 //! Handling of Mercurial-specific patterns. | 8 //! Handling of Mercurial-specific patterns. |
9 | 9 |
10 use crate::{utils::SliceExt, LineNumber, PatternError, PatternFileError}; | 10 use crate::{ |
11 utils::SliceExt, FastHashMap, LineNumber, PatternError, PatternFileError, | |
12 }; | |
11 use lazy_static::lazy_static; | 13 use lazy_static::lazy_static; |
12 use regex::bytes::{NoExpand, Regex}; | 14 use regex::bytes::{NoExpand, Regex}; |
13 use std::collections::HashMap; | |
14 use std::fs::File; | 15 use std::fs::File; |
15 use std::io::Read; | 16 use std::io::Read; |
16 use std::path::{Path, PathBuf}; | 17 use std::path::{Path, PathBuf}; |
17 use std::vec::Vec; | 18 use std::vec::Vec; |
18 | 19 |
212 Ok(_build_single_regex(enum_kind, pat, globsuffix)) | 213 Ok(_build_single_regex(enum_kind, pat, globsuffix)) |
213 } | 214 } |
214 } | 215 } |
215 | 216 |
216 lazy_static! { | 217 lazy_static! { |
217 static ref SYNTAXES: HashMap<&'static [u8], &'static [u8]> = { | 218 static ref SYNTAXES: FastHashMap<&'static [u8], &'static [u8]> = { |
218 let mut m = HashMap::new(); | 219 let mut m = FastHashMap::default(); |
219 | 220 |
220 m.insert(b"re".as_ref(), b"relre:".as_ref()); | 221 m.insert(b"re".as_ref(), b"relre:".as_ref()); |
221 m.insert(b"regexp".as_ref(), b"relre:".as_ref()); | 222 m.insert(b"regexp".as_ref(), b"relre:".as_ref()); |
222 m.insert(b"glob".as_ref(), b"relglob:".as_ref()); | 223 m.insert(b"glob".as_ref(), b"relglob:".as_ref()); |
223 m.insert(b"rootglob".as_ref(), b"rootglob:".as_ref()); | 224 m.insert(b"rootglob".as_ref(), b"rootglob:".as_ref()); |