From df05c5c3e20cfdfccd0165dd3370fed7c3676cd0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Sep 2018 15:39:28 +0300 Subject: [PATCH] Don't overflow when limiting symbol search --- crates/libanalysis/src/symbol_index.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/libanalysis/src/symbol_index.rs b/crates/libanalysis/src/symbol_index.rs index 8fef326ab8..4c93761aad 100644 --- a/crates/libanalysis/src/symbol_index.rs +++ b/crates/libanalysis/src/symbol_index.rs @@ -42,7 +42,7 @@ impl SymbolIndex { impl Query { pub(crate) fn search( - mut self, + self, indices: &[&SymbolIndex], token: &JobToken, ) -> Vec<(FileId, FileSymbol)> { @@ -55,7 +55,7 @@ impl Query { let mut stream = op.union(); let mut res = Vec::new(); while let Some((_, indexed_values)) = stream.next() { - if self.limit == 0 || token.is_canceled() { + if res.len() >= self.limit || token.is_canceled() { break; } for indexed_value in indexed_values { @@ -70,7 +70,6 @@ impl Query { continue; } res.push((*file_id, symbol.clone())); - self.limit -= 1; } } res