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

@ -1,7 +1,6 @@
use std::cell::RefCell;
use std::collections::VecDeque;
use std::rc::Rc;
use std::sync::OnceLock;
use std::{cell::RefCell, sync::LazyLock};
use anyhow::Result;
use markup5ever_rcdom::{Handle, NodeData};
@ -10,13 +9,14 @@ use regex::Regex;
use crate::html_element::HtmlElement;
fn empty_line_regex() -> &'static Regex {
static REGEX: OnceLock<Regex> = OnceLock::new();
REGEX.get_or_init(|| Regex::new(r"^\s*$").unwrap())
static REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^\s*$").expect("Failed to create empty_line_regex"));
&REGEX
}
fn more_than_three_newlines_regex() -> &'static Regex {
static REGEX: OnceLock<Regex> = OnceLock::new();
REGEX.get_or_init(|| Regex::new(r"\n{3,}").unwrap())
static REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\n{3,}").unwrap());
&REGEX
}
pub enum StartTagOutcome {