Add a fast path for when the search query is empty
This commit is contained in:
parent
a077210873
commit
6a0cca7178
1 changed files with 15 additions and 0 deletions
|
@ -55,6 +55,10 @@ impl SearchQuery {
|
|||
}
|
||||
|
||||
pub fn detect<T: Read>(&self, stream: T) -> Result<bool> {
|
||||
if self.as_str().is_empty() {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
match self {
|
||||
SearchQuery::Text { search, .. } => {
|
||||
let mat = search.stream_find_iter(stream).next();
|
||||
|
@ -89,6 +93,10 @@ impl SearchQuery {
|
|||
pub async fn search(&self, rope: &Rope) -> Vec<Range<usize>> {
|
||||
const YIELD_INTERVAL: usize = 20000;
|
||||
|
||||
if self.as_str().is_empty() {
|
||||
return Default::default();
|
||||
}
|
||||
|
||||
let mut matches = Vec::new();
|
||||
match self {
|
||||
SearchQuery::Text {
|
||||
|
@ -152,4 +160,11 @@ impl SearchQuery {
|
|||
}
|
||||
matches
|
||||
}
|
||||
|
||||
fn as_str(&self) -> &str {
|
||||
match self {
|
||||
SearchQuery::Text { query, .. } => query.as_str(),
|
||||
SearchQuery::Regex { regex, .. } => regex.as_str(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue