mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-05-19 09:40:22 -07:00
deps: drop thread_local, lazy_static and once_cell
This is largely made possible by the addition of std::sync::OnceLock to the standard library, and the memory pool available in regex-automata.
This commit is contained in:
parent
f16ea0812d
commit
6d17b3ed68
33
Cargo.lock
generated
33
Cargo.lock
generated
@ -143,7 +143,6 @@ dependencies = [
|
|||||||
"aho-corasick",
|
"aho-corasick",
|
||||||
"bstr",
|
"bstr",
|
||||||
"glob",
|
"glob",
|
||||||
"lazy_static",
|
|
||||||
"log",
|
"log",
|
||||||
"regex-automata",
|
"regex-automata",
|
||||||
"regex-syntax",
|
"regex-syntax",
|
||||||
@ -243,12 +242,10 @@ dependencies = [
|
|||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"crossbeam-deque",
|
"crossbeam-deque",
|
||||||
"globset",
|
"globset",
|
||||||
"lazy_static",
|
|
||||||
"log",
|
"log",
|
||||||
"memchr",
|
"memchr",
|
||||||
"regex",
|
"regex-automata",
|
||||||
"same-file",
|
"same-file",
|
||||||
"thread_local",
|
|
||||||
"walkdir",
|
"walkdir",
|
||||||
"winapi-util",
|
"winapi-util",
|
||||||
]
|
]
|
||||||
@ -288,12 +285,6 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lazy_static"
|
|
||||||
version = "1.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.148"
|
version = "0.2.148"
|
||||||
@ -346,12 +337,6 @@ dependencies = [
|
|||||||
"libm",
|
"libm",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "once_cell"
|
|
||||||
version = "1.18.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "packed_simd"
|
name = "packed_simd"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
@ -364,14 +349,13 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pcre2"
|
name = "pcre2"
|
||||||
version = "0.2.4"
|
version = "0.2.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "486aca7e74edb8cab09a48d461177f450a5cca3b55e61d139f7552190e2bbcf5"
|
checksum = "9deb1d02d6a373ee392128ba86087352a986359f32a106e2e3b08cc90cc659c9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"pcre2-sys",
|
"pcre2-sys",
|
||||||
"thread_local",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -447,7 +431,6 @@ dependencies = [
|
|||||||
"grep",
|
"grep",
|
||||||
"ignore",
|
"ignore",
|
||||||
"jemallocator",
|
"jemallocator",
|
||||||
"lazy_static",
|
|
||||||
"log",
|
"log",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
@ -543,16 +526,6 @@ dependencies = [
|
|||||||
"unicode-width",
|
"unicode-width",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "thread_local"
|
|
||||||
version = "1.1.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"once_cell",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.12"
|
version = "1.0.12"
|
||||||
|
@ -52,7 +52,6 @@ members = [
|
|||||||
bstr = "1.6.0"
|
bstr = "1.6.0"
|
||||||
grep = { version = "0.2.12", path = "crates/grep" }
|
grep = { version = "0.2.12", path = "crates/grep" }
|
||||||
ignore = { version = "0.4.19", path = "crates/ignore" }
|
ignore = { version = "0.4.19", path = "crates/ignore" }
|
||||||
lazy_static = "1.1.0"
|
|
||||||
log = "0.4.5"
|
log = "0.4.5"
|
||||||
serde_json = "1.0.23"
|
serde_json = "1.0.23"
|
||||||
termcolor = "1.1.0"
|
termcolor = "1.1.0"
|
||||||
@ -65,9 +64,6 @@ features = ["suggestions"]
|
|||||||
[target.'cfg(all(target_env = "musl", target_pointer_width = "64"))'.dependencies.jemallocator]
|
[target.'cfg(all(target_env = "musl", target_pointer_width = "64"))'.dependencies.jemallocator]
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
lazy_static = "1.1.0"
|
|
||||||
|
|
||||||
[build-dependencies.clap]
|
[build-dependencies.clap]
|
||||||
version = "2.33.0"
|
version = "2.33.0"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
// it into a ripgrep-specific configuration type that is not coupled with clap.
|
// it into a ripgrep-specific configuration type that is not coupled with clap.
|
||||||
|
|
||||||
use clap::{self, crate_authors, crate_version, App, AppSettings};
|
use clap::{self, crate_authors, crate_version, App, AppSettings};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
|
|
||||||
const ABOUT: &str = "
|
const ABOUT: &str = "
|
||||||
ripgrep (rg) recursively searches the current directory for a regex pattern.
|
ripgrep (rg) recursively searches the current directory for a regex pattern.
|
||||||
@ -47,18 +46,19 @@ OPTIONS:
|
|||||||
|
|
||||||
/// Build a clap application parameterized by usage strings.
|
/// Build a clap application parameterized by usage strings.
|
||||||
pub fn app() -> App<'static, 'static> {
|
pub fn app() -> App<'static, 'static> {
|
||||||
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
// We need to specify our version in a static because we've painted clap
|
// We need to specify our version in a static because we've painted clap
|
||||||
// into a corner. We've told it that every string we give it will be
|
// into a corner. We've told it that every string we give it will be
|
||||||
// 'static, but we need to build the version string dynamically. We can
|
// 'static, but we need to build the version string dynamically. We can
|
||||||
// fake the 'static lifetime with lazy_static.
|
// fake the 'static lifetime with lazy_static.
|
||||||
lazy_static! {
|
static LONG_VERSION: OnceLock<String> = OnceLock::new();
|
||||||
static ref LONG_VERSION: String = long_version(None, true);
|
let long_version = LONG_VERSION.get_or_init(|| long_version(None, true));
|
||||||
}
|
|
||||||
|
|
||||||
let mut app = App::new("ripgrep")
|
let mut app = App::new("ripgrep")
|
||||||
.author(crate_authors!())
|
.author(crate_authors!())
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.long_version(LONG_VERSION.as_str())
|
.long_version(long_version.as_str())
|
||||||
.about(ABOUT)
|
.about(ABOUT)
|
||||||
.max_term_width(100)
|
.max_term_width(100)
|
||||||
.setting(AppSettings::UnifiedHelpMessage)
|
.setting(AppSettings::UnifiedHelpMessage)
|
||||||
|
@ -37,7 +37,6 @@ features = ["std", "perf", "syntax", "meta", "nfa", "hybrid"]
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
glob = "0.3.1"
|
glob = "0.3.1"
|
||||||
lazy_static = "1"
|
|
||||||
serde_json = "1.0.107"
|
serde_json = "1.0.107"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -21,14 +21,16 @@ bench = false
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
crossbeam-deque = "0.8.3"
|
crossbeam-deque = "0.8.3"
|
||||||
globset = { version = "0.4.10", path = "../globset" }
|
globset = { version = "0.4.10", path = "../globset" }
|
||||||
lazy_static = "1.1"
|
|
||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
memchr = "2.6.3"
|
memchr = "2.6.3"
|
||||||
regex = { version = "1.9.5", default-features = false, features = ["perf", "std", "unicode-gencat"] }
|
|
||||||
same-file = "1.0.6"
|
same-file = "1.0.6"
|
||||||
thread_local = "1"
|
|
||||||
walkdir = "2.4.0"
|
walkdir = "2.4.0"
|
||||||
|
|
||||||
|
[dependencies.regex-automata]
|
||||||
|
version = "0.3.8"
|
||||||
|
default-features = false
|
||||||
|
features = ["std", "perf", "syntax", "meta", "nfa", "hybrid", "dfa-onepass"]
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies.winapi-util]
|
[target.'cfg(windows)'.dependencies.winapi-util]
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ the `git` command line tool.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
cell::RefCell,
|
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{BufRead, BufReader, Read},
|
io::{BufRead, BufReader, Read},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
@ -17,8 +16,7 @@ use std::{
|
|||||||
|
|
||||||
use {
|
use {
|
||||||
globset::{Candidate, GlobBuilder, GlobSet, GlobSetBuilder},
|
globset::{Candidate, GlobBuilder, GlobSet, GlobSetBuilder},
|
||||||
regex::bytes::Regex,
|
regex_automata::util::pool::Pool,
|
||||||
thread_local::ThreadLocal,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -86,7 +84,7 @@ pub struct Gitignore {
|
|||||||
globs: Vec<Glob>,
|
globs: Vec<Glob>,
|
||||||
num_ignores: u64,
|
num_ignores: u64,
|
||||||
num_whitelists: u64,
|
num_whitelists: u64,
|
||||||
matches: Option<Arc<ThreadLocal<RefCell<Vec<usize>>>>>,
|
matches: Option<Arc<Pool<Vec<usize>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Gitignore {
|
impl Gitignore {
|
||||||
@ -253,8 +251,7 @@ impl Gitignore {
|
|||||||
return Match::None;
|
return Match::None;
|
||||||
}
|
}
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
let _matches = self.matches.as_ref().unwrap().get_or_default();
|
let mut matches = self.matches.as_ref().unwrap().get();
|
||||||
let mut matches = _matches.borrow_mut();
|
|
||||||
let candidate = Candidate::new(path);
|
let candidate = Candidate::new(path);
|
||||||
self.set.matches_candidate_into(&candidate, &mut *matches);
|
self.set.matches_candidate_into(&candidate, &mut *matches);
|
||||||
for &i in matches.iter().rev() {
|
for &i in matches.iter().rev() {
|
||||||
@ -346,7 +343,7 @@ impl GitignoreBuilder {
|
|||||||
globs: self.globs.clone(),
|
globs: self.globs.clone(),
|
||||||
num_ignores: nignore as u64,
|
num_ignores: nignore as u64,
|
||||||
num_whitelists: nwhite as u64,
|
num_whitelists: nwhite as u64,
|
||||||
matches: Some(Arc::new(ThreadLocal::default())),
|
matches: Some(Arc::new(Pool::new(|| vec![]))),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,23 +593,28 @@ fn excludes_file_default() -> Option<PathBuf> {
|
|||||||
/// Extract git's `core.excludesfile` config setting from the raw file contents
|
/// Extract git's `core.excludesfile` config setting from the raw file contents
|
||||||
/// given.
|
/// given.
|
||||||
fn parse_excludes_file(data: &[u8]) -> Option<PathBuf> {
|
fn parse_excludes_file(data: &[u8]) -> Option<PathBuf> {
|
||||||
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
|
use regex_automata::{meta::Regex, util::syntax};
|
||||||
|
|
||||||
// N.B. This is the lazy approach, and isn't technically correct, but
|
// N.B. This is the lazy approach, and isn't technically correct, but
|
||||||
// probably works in more circumstances. I guess we would ideally have
|
// probably works in more circumstances. I guess we would ideally have
|
||||||
// a full INI parser. Yuck.
|
// a full INI parser. Yuck.
|
||||||
lazy_static::lazy_static! {
|
static RE: OnceLock<Regex> = OnceLock::new();
|
||||||
static ref RE: Regex = Regex::new(
|
let re = RE.get_or_init(|| {
|
||||||
r"(?xim-u)
|
Regex::builder()
|
||||||
^[[:space:]]*excludesfile[[:space:]]*
|
.configure(Regex::config().utf8_empty(false))
|
||||||
=
|
.syntax(syntax::Config::new().utf8(false))
|
||||||
[[:space:]]*(.+)[[:space:]]*$
|
.build(r"(?im-u)^\s*excludesfile\s*=\s*(\S+)\s*$")
|
||||||
"
|
.unwrap()
|
||||||
).unwrap();
|
});
|
||||||
};
|
// We don't care about amortizing allocs here I think. This should only
|
||||||
let caps = match RE.captures(data) {
|
// be called ~once per traversal or so? (Although it's not guaranteed...)
|
||||||
None => return None,
|
let mut caps = re.create_captures();
|
||||||
Some(caps) => caps,
|
re.captures(data, &mut caps);
|
||||||
};
|
let span = caps.get_group(1)?;
|
||||||
std::str::from_utf8(&caps[1]).ok().map(|s| PathBuf::from(expand_tilde(s)))
|
let candidate = &data[span];
|
||||||
|
std::str::from_utf8(candidate).ok().map(|s| PathBuf::from(expand_tilde(s)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Expands ~ in file paths to the value of $HOME.
|
/// Expands ~ in file paths to the value of $HOME.
|
||||||
|
@ -84,12 +84,11 @@ assert!(matcher.matched("y.cpp", false).is_whitelist());
|
|||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::{cell::RefCell, collections::HashMap, path::Path, sync::Arc};
|
use std::{collections::HashMap, path::Path, sync::Arc};
|
||||||
|
|
||||||
use {
|
use {
|
||||||
globset::{GlobBuilder, GlobSet, GlobSetBuilder},
|
globset::{GlobBuilder, GlobSet, GlobSetBuilder},
|
||||||
regex::Regex,
|
regex_automata::util::pool::Pool,
|
||||||
thread_local::ThreadLocal,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{default_types::DEFAULT_TYPES, pathutil::file_name, Error, Match};
|
use crate::{default_types::DEFAULT_TYPES, pathutil::file_name, Error, Match};
|
||||||
@ -178,7 +177,7 @@ pub struct Types {
|
|||||||
/// The set of all glob selections, used for actual matching.
|
/// The set of all glob selections, used for actual matching.
|
||||||
set: GlobSet,
|
set: GlobSet,
|
||||||
/// Temporary storage for globs that match.
|
/// Temporary storage for globs that match.
|
||||||
matches: Arc<ThreadLocal<RefCell<Vec<usize>>>>,
|
matches: Arc<Pool<Vec<usize>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indicates the type of a selection for a particular file type.
|
/// Indicates the type of a selection for a particular file type.
|
||||||
@ -232,7 +231,7 @@ impl Types {
|
|||||||
has_selected: false,
|
has_selected: false,
|
||||||
glob_to_selection: vec![],
|
glob_to_selection: vec![],
|
||||||
set: GlobSetBuilder::new().build().unwrap(),
|
set: GlobSetBuilder::new().build().unwrap(),
|
||||||
matches: Arc::new(ThreadLocal::default()),
|
matches: Arc::new(Pool::new(|| vec![])),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +279,7 @@ impl Types {
|
|||||||
return Match::None;
|
return Match::None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut matches = self.matches.get_or_default().borrow_mut();
|
let mut matches = self.matches.get();
|
||||||
self.set.matches_into(name, &mut *matches);
|
self.set.matches_into(name, &mut *matches);
|
||||||
// The highest precedent match is the last one.
|
// The highest precedent match is the last one.
|
||||||
if let Some(&i) = matches.last() {
|
if let Some(&i) = matches.last() {
|
||||||
@ -358,7 +357,7 @@ impl TypesBuilder {
|
|||||||
has_selected,
|
has_selected,
|
||||||
glob_to_selection,
|
glob_to_selection,
|
||||||
set,
|
set,
|
||||||
matches: Arc::new(ThreadLocal::default()),
|
matches: Arc::new(Pool::new(|| vec![])),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,10 +415,7 @@ impl TypesBuilder {
|
|||||||
/// If `name` is `all` or otherwise contains any character that is not a
|
/// If `name` is `all` or otherwise contains any character that is not a
|
||||||
/// Unicode letter or number, then an error is returned.
|
/// Unicode letter or number, then an error is returned.
|
||||||
pub fn add(&mut self, name: &str, glob: &str) -> Result<(), Error> {
|
pub fn add(&mut self, name: &str, glob: &str) -> Result<(), Error> {
|
||||||
lazy_static::lazy_static! {
|
if name == "all" || !name.chars().all(|c| c.is_alphanumeric()) {
|
||||||
static ref RE: Regex = Regex::new(r"^[\pL\pN]+$").unwrap();
|
|
||||||
};
|
|
||||||
if name == "all" || !RE.is_match(name) {
|
|
||||||
return Err(Error::InvalidDefinition);
|
return Err(Error::InvalidDefinition);
|
||||||
}
|
}
|
||||||
let (key, glob) = (name.to_string(), glob.to_string());
|
let (key, glob) = (name.to_string(), glob.to_string());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user