about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/src/search.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/search.rs b/src/tools/rust-analyzer/crates/ide-db/src/search.rs
index d9ffb173a0e..7319b7ac02d 100644
--- a/src/tools/rust-analyzer/crates/ide-db/src/search.rs
+++ b/src/tools/rust-analyzer/crates/ide-db/src/search.rs
@@ -503,6 +503,20 @@ impl<'a> FindUsages<'a> {
                 if !search_range.contains_inclusive(offset) {
                     return None;
                 }
+                // If this is not a word boundary, that means this is only part of an identifier,
+                // so it can't be what we're looking for.
+                // This speeds up short identifiers significantly.
+                if text[..idx]
+                    .chars()
+                    .next_back()
+                    .is_some_and(|ch| matches!(ch, 'A'..='Z' | 'a'..='z' | '_'))
+                    || text[idx + finder.needle().len()..]
+                        .chars()
+                        .next()
+                        .is_some_and(|ch| matches!(ch, 'A'..='Z' | 'a'..='z' | '_' | '0'..='9'))
+                {
+                    return None;
+                }
                 Some(offset)
             })
         }