Skip to content

Commit 028abfc

Browse files
committed
rewrite generate_without_disambiguation to do two copies only
it could be one-copy, but .to_lowercase() is probably much faster on strings than individual characters
1 parent 5f3d5eb commit 028abfc

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

lychee-lib/src/extract/fragments.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,19 @@ pub fn generate_without_disambiguation(text: &str) -> String {
4949
// Rust's to_lowercase handles the special cases as in
5050
// <https://www.unicode.org/Public/3.2-Update/SpecialCasing-3.2.0.txt>,
5151
// but GitHub's algorithm does not.
52-
let text = text
53-
.replace('Σ', "σ") // github does not emit GREEK SMALL LETTER FINAL SIGMA, rust does
54-
.replace('\u{0130}', "i") // github emits "i" for but rust emits "i\u{0307}"
55-
.to_lowercase();
56-
REGEX_TO_REMOVE.replace_all(&text, "").replace(' ', "-")
52+
REGEX_TO_REMOVE
53+
.split(&text)
54+
.flat_map(str::chars)
55+
.map(|c| {
56+
match c {
57+
' ' => '-',
58+
'\u{0130}' => 'i', // U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE
59+
'Σ' => 'σ', // U+03A3 GREEK CAPITAL LETTER SIGMA
60+
c => c,
61+
}
62+
})
63+
.collect::<String>()
64+
.to_lowercase()
5765
}
5866

5967
/// A stateful type for generating fragment identifiers in the style

0 commit comments

Comments
 (0)