Skip to content

Commit 322cd1f

Browse files
committed
Use multiple loops instead of Iterator::chain in FindUsages
1 parent 6630266 commit 322cd1f

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

crates/ide_db/src/search.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
//! get a super-set of matches. Then, we we confirm each match using precise
55
//! name resolution.
66
7-
use std::{convert::TryInto, iter, mem};
7+
use std::{convert::TryInto, mem};
88

99
use base_db::{FileId, FileRange, SourceDatabase, SourceDatabaseExt};
10-
use either::Either;
1110
use hir::{
1211
DefWithBody, HasAttrs, HasSource, InFile, ModuleDef, ModuleSource, Semantics, Visibility,
1312
};
@@ -370,37 +369,47 @@ impl<'a> FindUsages<'a> {
370369

371370
let tree = Lazy::new(|| sema.parse(file_id).syntax().clone());
372371

373-
let matches = text.match_indices(pat).chain(if search_for_self {
374-
Either::Left(text.match_indices("Self"))
375-
} else {
376-
Either::Right(iter::empty())
377-
});
378-
379-
for (idx, _) in matches {
372+
let mut handle_match = |idx: usize| -> bool {
380373
let offset: TextSize = idx.try_into().unwrap();
381374
if !search_range.contains_inclusive(offset) {
382-
continue;
375+
return false;
383376
}
384377

385378
if let Some(name) = sema.find_node_at_offset_with_descend(&tree, offset) {
386379
match name {
387380
ast::NameLike::NameRef(name_ref) => {
388381
if self.found_name_ref(&name_ref, sink) {
389-
return;
382+
return true;
390383
}
391384
}
392385
ast::NameLike::Name(name) => {
393386
if self.found_name(&name, sink) {
394-
return;
387+
return true;
395388
}
396389
}
397390
ast::NameLike::Lifetime(lifetime) => {
398391
if self.found_lifetime(&lifetime, sink) {
399-
return;
392+
return true;
400393
}
401394
}
402395
}
403396
}
397+
398+
return false;
399+
};
400+
401+
for (idx, _) in text.match_indices(pat) {
402+
if handle_match(idx) {
403+
return;
404+
}
405+
}
406+
407+
if search_for_self {
408+
for (idx, _) in text.match_indices("Self") {
409+
if handle_match(idx) {
410+
return;
411+
}
412+
}
404413
}
405414
}
406415
}

0 commit comments

Comments
 (0)