From 97f90da9bc514f86bcb662a4c7bbe8a68934fcdc Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 9 Nov 2020 19:27:25 -0600 Subject: [PATCH] refactor: Move off of lazy_static --- Cargo.lock | 8 +++++++- crates/typos/Cargo.toml | 2 +- crates/typos/src/tokens.rs | 20 ++++++++++---------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b019a97..ebc95ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -523,6 +523,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "once_cell" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" + [[package]] name = "phf" version = "0.8.0" @@ -982,8 +988,8 @@ dependencies = [ "derive_more 0.99.11", "derive_setters", "itertools", - "lazy_static", "log", + "once_cell", "regex", "serde", "serde_json", diff --git a/crates/typos/Cargo.toml b/crates/typos/Cargo.toml index e777c57..471cabe 100644 --- a/crates/typos/Cargo.toml +++ b/crates/typos/Cargo.toml @@ -18,7 +18,7 @@ codecov = { repository = "crate-ci/typos" } anyhow = "1.0" thiserror = "1.0" regex = "1.3" -lazy_static = "1.2.0" +once_cell = "1.2.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" itertools = "0.9" diff --git a/crates/typos/src/tokens.rs b/crates/typos/src/tokens.rs index 120eb4d..78b4c47 100644 --- a/crates/typos/src/tokens.rs +++ b/crates/typos/src/tokens.rs @@ -138,21 +138,21 @@ impl Default for Parser { } } +// `_`: number literal separator in Rust and other languages +// `'`: number literal separator in C++ +static DIGITS: once_cell::sync::Lazy = + once_cell::sync::Lazy::new(|| regex::bytes::Regex::new(r#"^[0-9_']+$"#).unwrap()); + fn is_number(ident: &[u8]) -> bool { - lazy_static::lazy_static! { - // `_`: number literal separator in Rust and other languages - // `'`: number literal separator in C++ - static ref DIGITS: regex::bytes::Regex = regex::bytes::Regex::new(r#"^[0-9_']+$"#).unwrap(); - } DIGITS.is_match(ident) } +// `_`: number literal separator in Rust and other languages +// `'`: number literal separator in C++ +static HEX: once_cell::sync::Lazy = + once_cell::sync::Lazy::new(|| regex::bytes::Regex::new(r#"^0[xX][0-9a-fA-F_']+$"#).unwrap()); + fn is_hex(ident: &[u8]) -> bool { - lazy_static::lazy_static! { - // `_`: number literal separator in Rust and other languages - // `'`: number literal separator in C++ - static ref HEX: regex::bytes::Regex = regex::bytes::Regex::new(r#"^0[xX][0-9a-fA-F_']+$"#).unwrap(); - } HEX.is_match(ident) }