Skip to content

Commit 0a96d0e

Browse files
authored
Merge pull request #2290 from klensy/less-clones
removes few more allocs
2 parents 59d3717 + e3ad9d0 commit 0a96d0e

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/renderer/html_handlebars/hbs_renderer.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,9 @@ fn add_playground_pre(
935935
/// Modifies all `<code>` blocks to convert "hidden" lines and to wrap them in
936936
/// a `<span class="boring">`.
937937
fn hide_lines(html: &str, code_config: &Code) -> String {
938-
let language_regex = Regex::new(r"\blanguage-(\w+)\b").unwrap();
939-
let hidelines_regex = Regex::new(r"\bhidelines=(\S+)").unwrap();
938+
static LANGUAGE_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\blanguage-(\w+)\b").unwrap());
939+
static HIDELINES_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\bhidelines=(\S+)").unwrap());
940+
940941
CODE_BLOCK_RE
941942
.replace_all(html, |caps: &Captures<'_>| {
942943
let text = &caps[1];
@@ -951,12 +952,12 @@ fn hide_lines(html: &str, code_config: &Code) -> String {
951952
)
952953
} else {
953954
// First try to get the prefix from the code block
954-
let hidelines_capture = hidelines_regex.captures(classes);
955+
let hidelines_capture = HIDELINES_REGEX.captures(classes);
955956
let hidelines_prefix = match &hidelines_capture {
956957
Some(capture) => Some(&capture[1]),
957958
None => {
958959
// Then look up the prefix by language
959-
language_regex.captures(classes).and_then(|capture| {
960+
LANGUAGE_REGEX.captures(classes).and_then(|capture| {
960961
code_config.hidelines.get(&capture[1]).map(|p| p.as_str())
961962
})
962963
}

src/renderer/html_handlebars/helpers/navigation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn find_chapter(
103103
}
104104
}
105105

106-
previous = Some(item.clone());
106+
previous = Some(item);
107107
}
108108
_ => continue,
109109
}

0 commit comments

Comments
 (0)