optimize cropping

This commit is contained in:
marin postma 2021-06-20 16:59:31 +02:00
parent c1b6f0e833
commit 3a2e7d3c3b
No known key found for this signature in database
GPG Key ID: 6088B7721C3E39F9

View File

@ -496,18 +496,19 @@ impl<'a, A: AsRef<[u8]>> Formatter<'a, A> {
tokens
.map(|(word, token)| {
if format_options.highlight && token.is_word() && matcher.matches(token.text()).is_some() {
let mut new_word = String::new();
new_word.push_str(&self.marks.0);
if let Some(match_len) = matcher.matches(token.text()) {
if let Some(match_len) = matcher.matches(token.text()) {
if format_options.highlight && token.is_word() {
let mut new_word = String::new();
new_word.push_str(&self.marks.0);
new_word.push_str(&word[..match_len]);
new_word.push_str(&self.marks.1);
new_word.push_str(&word[match_len..]);
return Cow::Owned(new_word)
}
Cow::Owned(new_word)
} else {
Cow::Borrowed(word)
}
Cow::Borrowed(word)
})
.collect::<String>()
}