Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

project: Simplify file search logic (#47982)

Xiaobo Liu0e118ac9ae05
diff --git a/crates/project/src/search.rs b/crates/project/src/search.rs
index a64172928fb..3a554eb3da1 100644
--- a/crates/project/src/search.rs
+++ b/crates/project/src/search.rs
@@ -335,26 +335,21 @@ impl SearchQuery {
mut reader: BufReader<Box<dyn Read + Send + Sync>>,
) -> Result<bool> {
let query_str = self.as_str();
- let needle_len = query_str.len();
- if needle_len == 0 {
- return Ok(false);
- }
- if self.as_str().is_empty() {
+ if query_str.is_empty() {
return Ok(false);
}
- let mut text = String::new();
- let mut bytes_read = 0;
// Yield from this function every 20KB scanned.
const YIELD_THRESHOLD: usize = 20 * 1024;
+
match self {
Self::Text { search, .. } => {
+ let mut text = String::new();
if query_str.contains('\n') {
reader.read_to_string(&mut text)?;
Ok(search.is_match(&text))
} else {
- // Yield from this function every 20KB scanned.
- const YIELD_THRESHOLD: usize = 20 * 1024;
+ let mut bytes_read = 0;
while reader.read_line(&mut text)? > 0 {
if search.is_match(&text) {
return Ok(true);
@@ -372,13 +367,12 @@ impl SearchQuery {
Self::Regex {
regex, multiline, ..
} => {
+ let mut text = String::new();
if *multiline {
- if let Err(err) = reader.read_to_string(&mut text) {
- Err(err.into())
- } else {
- Ok(regex.is_match(&text)?)
- }
+ reader.read_to_string(&mut text)?;
+ Ok(regex.is_match(&text)?)
} else {
+ let mut bytes_read = 0;
while reader.read_line(&mut text)? > 0 {
if regex.is_match(&text)? {
return Ok(true);