summaryrefslogtreecommitdiffstats
path: root/src/pattern
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2021-03-09 16:30:54 +0100
committerCanop <cano.petrole@gmail.com>2021-03-09 16:30:54 +0100
commitd8bc06df60b1d8b3efd1f72e9d4de6141eccc93d (patch)
tree1550f2b26442d2f078553e875c402bc308a4e8a7 /src/pattern
parentd41c534bb43fbf23eecfcd6232300e3685df82d1 (diff)
use smallvec for char positions in namematchs
Diffstat (limited to 'src/pattern')
-rw-r--r--src/pattern/exact_pattern.rs3
-rw-r--r--src/pattern/fuzzy_pattern.rs3
-rw-r--r--src/pattern/name_match.rs5
-rw-r--r--src/pattern/regex_pattern.rs3
4 files changed, 10 insertions, 4 deletions
diff --git a/src/pattern/exact_pattern.rs b/src/pattern/exact_pattern.rs
index e377e1d..23c6e3e 100644
--- a/src/pattern/exact_pattern.rs
+++ b/src/pattern/exact_pattern.rs
@@ -4,6 +4,7 @@
use {
super::NameMatch,
+ smallvec::SmallVec,
std::fmt,
};
@@ -68,7 +69,7 @@ impl ExactPattern {
// we must find the start in chars, not bytes
for (char_idx, (byte_idx, _)) in candidate.char_indices().enumerate() {
if byte_idx == start {
- let mut pos = Vec::with_capacity(self.chars_count);
+ let mut pos = SmallVec::with_capacity(self.chars_count);
for i in 0..self.chars_count {
pos.push(i + char_idx);
}
diff --git a/src/pattern/fuzzy_pattern.rs b/src/pattern/fuzzy_pattern.rs
index 58c78b0..ca35fea 100644
--- a/src/pattern/fuzzy_pattern.rs
+++ b/src/pattern/fuzzy_pattern.rs
@@ -5,6 +5,7 @@
use {
super::NameMatch,
secular,
+ smallvec::SmallVec,
std::fmt::{self, Write},
};
@@ -79,7 +80,7 @@ impl FuzzyPattern {
if cand_chars[start_idx] != self.chars[0] {
return MatchSearchResult::None;
}
- let mut pos: Vec<usize> = vec![]; // positions of matching chars in candidate
+ let mut pos: SmallVec<[usize;12]> = SmallVec::with_capacity(self.chars.len()); // positions of matching chars in candidate
pos.push(start_idx);
let mut d = 1;
let mut nb_holes = 0;
diff --git a/src/pattern/name_match.rs b/src/pattern/name_match.rs
index 30f61a9..402e4e3 100644
--- a/src/pattern/name_match.rs
+++ b/src/pattern/name_match.rs
@@ -1,10 +1,13 @@
+use {
+ smallvec::SmallVec,
+};
/// A NameMatch is a positive result of pattern matching inside
/// a filename or subpath
#[derive(Debug, Clone)]
pub struct NameMatch {
pub score: i32, // score of the match, guaranteed strictly positive, bigger is better
- pub pos: Vec<usize>, // positions of the matching chars
+ pub pos: SmallVec<[usize; 12]>, // positions of the matching chars
}
impl NameMatch {
diff --git a/src/pattern/regex_pattern.rs b/src/pattern/regex_pattern.rs
index 1fc2417..f78f410 100644
--- a/src/pattern/regex_pattern.rs
+++ b/src/pattern/regex_pattern.rs
@@ -4,6 +4,7 @@ use {
super::NameMatch,
crate::errors::PatternError,
regex,
+ smallvec::SmallVec,
std::fmt,
};
@@ -31,7 +32,7 @@ impl RegexPattern {
// note that there's no significative cost related to using
// find over is_match
self.rex.find(candidate).map(|rm| {
- let mut pos = Vec::with_capacity(rm.end() - rm.start());
+ let mut pos = SmallVec::with_capacity(rm.end() - rm.start());
for i in rm.start()..rm.end() {
pos.push(i);
}