Use static LazyLocks for all constant regexes (#22225)

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2024-12-18 19:20:35 -07:00 committed by GitHub
parent 837bbc851f
commit b93cee8d27
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 43 additions and 33 deletions

View file

@ -9,7 +9,7 @@ pub mod test;
use futures::Future;
use regex::Regex;
use std::sync::OnceLock;
use std::sync::{LazyLock, OnceLock};
use std::{
borrow::Cow,
cmp::{self, Ordering},
@ -567,8 +567,9 @@ impl<'a> PartialOrd for NumericPrefixWithSuffix<'a> {
}
fn emoji_regex() -> &'static Regex {
static EMOJI_REGEX: OnceLock<Regex> = OnceLock::new();
EMOJI_REGEX.get_or_init(|| Regex::new("(\\p{Emoji}|\u{200D})").unwrap())
static EMOJI_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new("(\\p{Emoji}|\u{200D})").unwrap());
&EMOJI_REGEX
}
/// Returns true if the given string consists of emojis only.