mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +00:00
Test for word boundary in FindUsages
This speeds up short identifiers search significantly, while unlikely to have an effect on long identifiers (the analysis takes much longer than some character comparison). Tested by finding all references to `eq()` (from `PartialEq`) in the rust-analyzer repo. Total time went down from 100s to 10s (a 10x reduction!).
This commit is contained in:
parent
0daeb5c0b0
commit
1a31fe299b
1 changed files with 14 additions and 0 deletions
|
@ -503,6 +503,20 @@ impl<'a> FindUsages<'a> {
|
||||||
if !search_range.contains_inclusive(offset) {
|
if !search_range.contains_inclusive(offset) {
|
||||||
return None;
|
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)
|
Some(offset)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue