Skip to content

Commit

Permalink
Rollup merge of #114351 - ttsugriy:sort-by-words, r=fee1-dead
Browse files Browse the repository at this point in the history
[rustc_span][perf] Remove unnecessary string joins and allocs.

Comparing vectors of string parts yields the same result but avoids unnecessary `join` and potential allocation for resulting `String`. This code is cold so it's unlikely to have any measurable impact, but considering but since it's also simpler, why not? :)
  • Loading branch information
matthiaskrgr committed Aug 4, 2023
2 parents 5054e41 + f74eee2 commit 23e86f6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_span/src/edit_distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ fn find_match_by_sorted_words(iter_names: &[Symbol], lookup: &str) -> Option<Sym
})
}

fn sort_by_words(name: &str) -> String {
fn sort_by_words(name: &str) -> Vec<&str> {
let mut split_words: Vec<&str> = name.split('_').collect();
// We are sorting primitive &strs and can use unstable sort here.
split_words.sort_unstable();
split_words.join("_")
split_words
}

0 comments on commit 23e86f6

Please sign in to comment.