Skip to content

Commit 07b2346

Browse files
committed
make resolve_path lazyish again by boxing the iterator
1 parent 40ed626 commit 07b2346

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/racer/nameres.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -539,19 +539,23 @@ pub fn do_local_search_with_string(path: &[&str], filepath: &Path, pos: uint,
539539
// HACK: Make box iterator support iterator trait
540540
//
541541
// I can't get the type signature to resolve_name to compile, so instead am boxing it into a trait object and then returning it as an iterator
542-
pub struct BoxIter {
543-
iter: Box<Iterator<Match>>
542+
pub struct BoxIter<T> {
543+
iter: Box<Iterator<T>>
544544
}
545545

546-
impl Iterator<Match> for BoxIter {
546+
impl<T> Iterator<T> for BoxIter<T> {
547547
#[inline]
548-
fn next(&mut self) -> Option<Match> {
548+
fn next(&mut self) -> Option<T> {
549549
return self.iter.next();
550550
}
551551
}
552552

553+
pub fn wrap_boxed_iter<T>(boxediter: Box<Iterator<T>>) -> BoxIter<T> {
554+
return BoxIter{ iter: boxediter };
555+
}
556+
553557
pub fn resolve_name(searchstr: &str, filepath: &Path, pos: uint,
554-
search_type: SearchType, namespace: Namespace) -> BoxIter {
558+
search_type: SearchType, namespace: Namespace) -> BoxIter<Match> {
555559
let msrc = racer::load_file_and_mask_comments(filepath);
556560

557561
let s = String::from_str(searchstr);
@@ -628,18 +632,14 @@ pub fn resolve_name(searchstr: &str, filepath: &Path, pos: uint,
628632

629633

630634
pub fn resolve_path(path: &[&str], filepath: &Path, pos: uint,
631-
search_type: SearchType, namespace: Namespace) -> vec::MoveItems<Match> {
635+
search_type: SearchType, namespace: Namespace) -> BoxIter<Match> {
632636
debug!("PHIL do_local_search path {} in {}",path, filepath.as_str());
633637

634-
let mut out = Vec::new();
635-
636638
if path.len() == 1 {
637639
let searchstr = path[0];
638-
for m in resolve_name(searchstr, filepath, pos, search_type, namespace) {
639-
out.push(m);
640-
}
641-
return out.move_iter();
640+
return resolve_name(searchstr, filepath, pos, search_type, namespace);
642641
} else {
642+
let mut out = Vec::new();
643643
if path[0] == "" {
644644
// match global searches starting with :: - e.g. ::std::blah::...
645645
for m in do_external_search(path.slice_from(1), filepath, pos, search_type, namespace) {
@@ -688,7 +688,7 @@ pub fn resolve_path(path: &[&str], filepath: &Path, pos: uint,
688688
}
689689
});
690690

691-
return out.move_iter();
691+
return BoxIter{iter: box out.move_iter() as Box<Iterator<Match>>};
692692
}
693693
}
694694

0 commit comments

Comments
 (0)