Replace once_cell with stdlib
Before adoption: this commit came in with the history the project adopted, so no landing records it.
LazyLock isn't standardized yet, but OnceLock is good enough for what we need.
authored by Thayne McCombs · committed by Thayne McCombs · parent d6e9cbf · Browse files · 5 files·+15 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+15 added−15 removed
- other:+15 added−15 removed
Provenance
- Commit
91e3c3c- Tree
0aa1d02- Author
Thayne McCombs <astrothayne@gmail.com>- Committer
Thayne McCombs <astrothayne@gmail.com>- Parent
d6e9cbf
5 files changed+15 added−15 removed
modified:src/exec/mod.rs+6 added-5 removed
7 unmodified lines8 use std::io;9 use std::iter;10 use std::path::{Component, Path, PathBuf, Prefix};11 use std::process::Stdio;12-use std::sync::Mutex;12+use std::sync::{Mutex, OnceLock};13 14 use anyhow::{bail, Result};15 use argmax::Command;16-use once_cell::sync::Lazy;16 use regex::Regex;17 18 use crate::exit_codes::{merge_exitcodes, ExitCode};19 209 unmodified lines229 where230 I: IntoIterator<Item = S>,231 S: AsRef<str>,232 {234- static PLACEHOLDER_PATTERN: Lazy<Regex> =235- Lazy::new(|| Regex::new(r"\{(/?\.?|//)\}").unwrap());233+ static PLACEHOLDER_PATTERN: OnceLock<Regex> = OnceLock::new();234 235 let mut args = Vec::new();236 let mut has_placeholder = false;237 2 unmodified lines240 241 let mut tokens = Vec::new();242 let mut start = 0;243 244+ let pattern =245+ PLACEHOLDER_PATTERN.get_or_init(|| Regex::new(r"\{(/?\.?|//)\}").unwrap());246+246- for placeholder in PLACEHOLDER_PATTERN.find_iter(arg) {247+ for placeholder in pattern.find_iter(arg) {248 // Leading text before the placeholder.249 if placeholder.start() > start {250 tokens.push(Token::Text(arg[start..placeholder.start()].to_owned()));251 }346 unmodified linesmodified:src/filter/size.rs+7 added-5 removed
1+use std::sync::OnceLock;2+3 use anyhow::anyhow;2-use once_cell::sync::Lazy;4 use regex::Regex;5 5-static SIZE_CAPTURES: Lazy<Regex> =6- Lazy::new(|| Regex::new(r"(?i)^([+-]?)(\d+)(b|[kmgt]i?b?)$").unwrap());6+static SIZE_CAPTURES: OnceLock<Regex> = OnceLock::new();7 8 #[derive(Clone, Copy, Debug, PartialEq, Eq)]9 pub enum SizeFilter {10 Max(u64),19 unmodified lines30 .ok_or_else(|| anyhow!("'{}' is not a valid size constraint. See 'fd --help'.", s))31 }32 33 fn parse_opt(s: &str) -> Option<Self> {34+ let pattern =35+ SIZE_CAPTURES.get_or_init(|| Regex::new(r"(?i)^([+-]?)(\d+)(b|[kmgt]i?b?)$").unwrap());34- if !SIZE_CAPTURES.is_match(s) {36+ if !pattern.is_match(s) {37 return None;38 }39 38- let captures = SIZE_CAPTURES.captures(s)?;40+ let captures = pattern.captures(s)?;41 let limit_kind = captures.get(1).map_or("+", |m| m.as_str());42 let quantity = captures43 .get(2)44 .and_then(|v| v.as_str().parse::<u64>().ok())?;175 unmodified linesmodified:src/dir_entry.rs+1 added-2 removed
1+use std::cell::OnceCell;2 use std::ffi::OsString;3 use std::fs::{FileType, Metadata};4 use std::path::{Path, PathBuf};5 6 use lscolors::{Colorable, LsColors, Style};7 7-use once_cell::unsync::OnceCell;8-8 use crate::config::Config;9 use crate::filesystem::strip_current_dir;10 11 enum DirEntryInner {142 unmodified linesmodified:Cargo.lock-1 removed
345 unmodified lines346 "nix 0.26.2",347 "normpath",348 "nu-ansi-term",349 "num_cpus",350- "once_cell",350 "regex",351 "regex-syntax",352 "tempfile",353 "test-case",851 unmodified linesmodified:Cargo.toml+1 added-2 removed
16 unmodified lines1718192021212223242520 unmodified lines46474849505051525343 unmodified lines16 unmodified linesreadme = "README.md"repository = "https://github.com/sharkdp/fd"version = "8.7.0"edition= "2021"rust-version = "1.67.0"rust-version = "1.70.0"
[badges.appveyor]repository = "sharkdp/fd"
20 unmodified linesglobset = "0.4"anyhow = "1.0"dirs-next = "2.0"normpath = "1.1.1"once_cell = "1.17.2"crossbeam-channel = "0.5.8"clap_complete = {version = "4.3.0", optional = true}faccess = "0.2.4"
43 unmodified lines