Skip to content

Commit ea78953

Browse files
committed
feat: match loop performance by up to 15%
1 parent 98c215b commit ea78953

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

bmatcher-core/src/matcher.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,19 @@ impl<'a> BinaryMatcher<'a> {
181181
/// Subsequent elements can be pushed using the `Atom::SaveCursor` atom or the `'` command within the binary pattern.
182182
/// - `None` if no further matches are available.
183183
pub fn next_match(&mut self) -> Option<&[u32]> {
184-
while self.match_offset < self.target.match_length() {
185-
let offset = self.match_offset;
186-
self.match_offset += 1;
187-
184+
for match_offset in self.match_offset..self.target.match_length() {
188185
self.save_stack.truncate(1);
189-
self.save_stack[0] = offset as u32;
190-
191186
self.cursor_stack.truncate(0);
192187

193-
if self.match_atoms(offset, self.pattern.atoms()).is_none() {
188+
if self
189+
.match_atoms(match_offset, self.pattern.atoms())
190+
.is_none()
191+
{
194192
continue;
195193
}
196194

195+
self.match_offset = match_offset + 1;
196+
self.save_stack[0] = match_offset as u32;
197197
return Some(&self.save_stack);
198198
}
199199

0 commit comments

Comments
 (0)