about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2022-01-17 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2022-01-26 10:43:01 +0100
commitf93bd000a35bee3ae18225d348d2d16c123aea53 (patch)
treec56cb67b526360db4128b65020bc5b67c4414b1b
parentd502eda250d0090f4990cc6880c88b95a92b4818 (diff)
downloadrust-f93bd000a35bee3ae18225d348d2d16c123aea53.tar.gz
rust-f93bd000a35bee3ae18225d348d2d16c123aea53.zip
Hoist `to_uppercase` out of the loop
-rw-r--r--compiler/rustc_span/src/lev_distance.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/compiler/rustc_span/src/lev_distance.rs b/compiler/rustc_span/src/lev_distance.rs
index aed699e4839..6554312b8b9 100644
--- a/compiler/rustc_span/src/lev_distance.rs
+++ b/compiler/rustc_span/src/lev_distance.rs
@@ -56,6 +56,7 @@ pub fn find_best_match_for_name(
     dist: Option<usize>,
 ) -> Option<Symbol> {
     let lookup = lookup.as_str();
+    let lookup_uppercase = lookup.to_uppercase();
     let max_dist = dist.unwrap_or_else(|| cmp::max(lookup.len(), 3) / 3);
 
     // Priority of matches:
@@ -63,7 +64,7 @@ pub fn find_best_match_for_name(
     // 2. Levenshtein distance match
     // 3. Sorted word match
     if let Some(case_insensitive_match) =
-        name_vec.iter().find(|candidate| candidate.as_str().to_uppercase() == lookup.to_uppercase())
+        name_vec.iter().find(|candidate| candidate.as_str().to_uppercase() == lookup_uppercase)
     {
         return Some(*case_insensitive_match);
     }