Skip to content
Myr

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

5 files+15 added−15 removed

modified:src/exec/mod.rs+6 added-5 removed
7 unmodified lines
8use std::io;9use std::iter;10use std::path::{Component, Path, PathBuf, Prefix};11use std::process::Stdio;12use std::sync::Mutex;12use std::sync::{Mutex, OnceLock};1314use anyhow::{bail, Result};15use argmax::Command;16use once_cell::sync::Lazy;16use regex::Regex;1718use crate::exit_codes::{merge_exitcodes, ExitCode};19
209 unmodified lines
229 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();234235 let mut args = Vec::new();236 let mut has_placeholder = false;237
2 unmodified lines
240241 let mut tokens = Vec::new();242 let mut start = 0;243244 let pattern =245 PLACEHOLDER_PATTERN.get_or_init(|| Regex::new(r"\{(/?\.?|//)\}").unwrap());246246 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 lines
modified:src/filter/size.rs+7 added-5 removed
1use std::sync::OnceLock;23use anyhow::anyhow;2use once_cell::sync::Lazy;4use regex::Regex;55static SIZE_CAPTURES: Lazy<Regex> =6 Lazy::new(|| Regex::new(r"(?i)^([+-]?)(\d+)(b|[kmgt]i?b?)$").unwrap());6static SIZE_CAPTURES: OnceLock<Regex> = OnceLock::new();78#[derive(Clone, Copy, Debug, PartialEq, Eq)]9pub enum SizeFilter {10 Max(u64),
19 unmodified lines
30 .ok_or_else(|| anyhow!("'{}' is not a valid size constraint. See 'fd --help'.", s))31 }3233 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 }3938 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 lines
modified:src/dir_entry.rs+1 added-2 removed
1use std::cell::OnceCell;2use std::ffi::OsString;3use std::fs::{FileType, Metadata};4use std::path::{Path, PathBuf};56use lscolors::{Colorable, LsColors, Style};77use once_cell::unsync::OnceCell;88use crate::config::Config;9use crate::filesystem::strip_current_dir;1011enum DirEntryInner {
142 unmodified lines
modified:Cargo.lock-1 removed
345 unmodified lines
346 "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 lines
modified:Cargo.toml+1 added-2 removed