Use static LazyLocks for all constant regexes (#22225)
Release Notes: - N/A
This commit is contained in:
parent
837bbc851f
commit
b93cee8d27
6 changed files with 43 additions and 33 deletions
|
@ -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"));
|
||||
®EX
|
||||
}
|
||||
|
||||
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());
|
||||
®EX
|
||||
}
|
||||
|
||||
pub enum StartTagOutcome {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue