rustdoc: Reduce allocations in a theme function

This commit is contained in:
Roc Yu 2022-04-10 19:17:38 -04:00
parent 027a232755
commit 7feb7383d2
No known key found for this signature in database
GPG Key ID: 5068CE514A79D27F

View File

@ -173,15 +173,17 @@ fn build_rule(v: &[u8], positions: &[usize]) -> String {
.map(|x| ::std::str::from_utf8(&v[x[0]..x[1]]).unwrap_or(""))
.collect::<String>()
.trim()
.replace('\n', " ")
.replace('/', "")
.replace('\t', " ")
.replace('{', "")
.replace('}', "")
.chars()
.filter_map(|c| match c {
'\n' | '\t' => Some(' '),
'/' | '{' | '}' => None,
c => Some(c),
})
.collect::<String>()
.split(' ')
.filter(|s| !s.is_empty())
.collect::<Vec<&str>>()
.join(" "),
.intersperse(" ")
.collect::<String>(),
)
.unwrap_or_else(|_| String::new())
}