reduce useless regex allocs
from 474mb to 215mb ==40876== Total: 474,156,323 bytes in 1,521,025 blocks ==40876== At t-gmax: 13,872,954 bytes in 4,655 blocks ==40876== At t-end: 488,516 bytes in 884 blocks ==40876== Reads: 820,933,434 bytes ==40876== Writes: 514,838,350 bytes to ==57763== Total: 215,292,393 bytes in 1,161,048 blocks ==57763== At t-gmax: 13,872,954 bytes in 4,655 blocks ==57763== At t-end: 1,210,783 bytes in 1,274 blocks ==57763== Reads: 598,542,892 bytes ==57763== Writes: 229,841,910 bytes
This commit is contained in:
parent
573b6522f9
commit
e3ad9d097e
|
@ -935,8 +935,9 @@ fn add_playground_pre(
|
||||||
/// Modifies all `<code>` blocks to convert "hidden" lines and to wrap them in
|
/// Modifies all `<code>` blocks to convert "hidden" lines and to wrap them in
|
||||||
/// a `<span class="boring">`.
|
/// a `<span class="boring">`.
|
||||||
fn hide_lines(html: &str, code_config: &Code) -> String {
|
fn hide_lines(html: &str, code_config: &Code) -> String {
|
||||||
let language_regex = Regex::new(r"\blanguage-(\w+)\b").unwrap();
|
static LANGUAGE_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\blanguage-(\w+)\b").unwrap());
|
||||||
let hidelines_regex = Regex::new(r"\bhidelines=(\S+)").unwrap();
|
static HIDELINES_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\bhidelines=(\S+)").unwrap());
|
||||||
|
|
||||||
CODE_BLOCK_RE
|
CODE_BLOCK_RE
|
||||||
.replace_all(html, |caps: &Captures<'_>| {
|
.replace_all(html, |caps: &Captures<'_>| {
|
||||||
let text = &caps[1];
|
let text = &caps[1];
|
||||||
|
@ -951,12 +952,12 @@ fn hide_lines(html: &str, code_config: &Code) -> String {
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// First try to get the prefix from the code block
|
// First try to get the prefix from the code block
|
||||||
let hidelines_capture = hidelines_regex.captures(classes);
|
let hidelines_capture = HIDELINES_REGEX.captures(classes);
|
||||||
let hidelines_prefix = match &hidelines_capture {
|
let hidelines_prefix = match &hidelines_capture {
|
||||||
Some(capture) => Some(&capture[1]),
|
Some(capture) => Some(&capture[1]),
|
||||||
None => {
|
None => {
|
||||||
// Then look up the prefix by language
|
// Then look up the prefix by language
|
||||||
language_regex.captures(classes).and_then(|capture| {
|
LANGUAGE_REGEX.captures(classes).and_then(|capture| {
|
||||||
code_config.hidelines.get(&capture[1]).map(|p| p.as_str())
|
code_config.hidelines.get(&capture[1]).map(|p| p.as_str())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue