Skip to content

Commit 5ad661c

Browse files
committed
perf: replace emoji loop with single-pass replace_all closure
1 parent 9e327f1 commit 5ad661c

1 file changed

Lines changed: 1 addition & 9 deletions

File tree

src/utils.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,15 +1093,7 @@ pub fn rewrite_urls(input_text: &str) -> String {
10931093
// Rewrite Reddit links to Redlib
10941094
REDDIT_REGEX.replace_all(input_text, r#"href="/"#).to_string();
10951095

1096-
loop {
1097-
if REDDIT_EMOJI_REGEX.find(&text1).is_none() {
1098-
break;
1099-
} else {
1100-
text1 = REDDIT_EMOJI_REGEX
1101-
.replace_all(&text1, format_url(REDDIT_EMOJI_REGEX.find(&text1).map(|x| x.as_str()).unwrap_or_default()))
1102-
.to_string()
1103-
}
1104-
}
1096+
text1 = REDDIT_EMOJI_REGEX.replace_all(&text1, |caps: &regex::Captures| format_url(&caps[0])).to_string();
11051097

11061098
// Remove (html-encoded) "\" from URLs.
11071099
text1 = text1.replace("%5C", "").replace("\\_", "_");

0 commit comments

Comments
 (0)