about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-08-04 21:31:56 +0200
committerGitHub <noreply@github.com>2023-08-04 21:31:56 +0200
commit23e86f6ef8d5576a655cbba4b68f1f3103e69d27 (patch)
tree161ac36ffd24e3428016e583b2f1c921f25ec532
parent5054e41b642fb6da0094034e56ae65d98e8bb884 (diff)
parentf74eee2fa6620ecb88070ed2eb2dfd7ba12e0b63 (diff)
downloadrust-23e86f6ef8d5576a655cbba4b68f1f3103e69d27.tar.gz
rust-23e86f6ef8d5576a655cbba4b68f1f3103e69d27.zip
Rollup merge of #114351 - ttsugriy:sort-by-words, r=fee1-dead
[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? :)
-rw-r--r--compiler/rustc_span/src/edit_distance.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/rustc_span/src/edit_distance.rs b/compiler/rustc_span/src/edit_distance.rs
index 4811bb2c354..96a118e590f 100644
--- a/compiler/rustc_span/src/edit_distance.rs
+++ b/compiler/rustc_span/src/edit_distance.rs
@@ -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
 }