From a6d4fda5823c1766343e96109dad89c1e84cab2e Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Sun, 13 Nov 2022 12:40:39 -0800 Subject: [PATCH] Minor re-arrangement for compatibiility. --- crates/squozen/bench/bench_patprep.rs | 6 ++++-- crates/squozen/src/prepare_pattern.rs | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/squozen/bench/bench_patprep.rs b/crates/squozen/bench/bench_patprep.rs index c4fd1f2..4e09fd0 100644 --- a/crates/squozen/bench/bench_patprep.rs +++ b/crates/squozen/bench/bench_patprep.rs @@ -1,11 +1,13 @@ -use squozen::prepare_pattern::prepare_pattern; +use squozen::prepare_pattern::prepare_pattern_raw; const COUNT: usize = 5 * 1000 * 1000 * 100; fn main() { let mut end = COUNT; + let mut dest = Vec::::with_capacity(100); while end > 0 { - let _g = prepare_pattern(b"/foo/bar/whatever[0-9]*"); + dest.clear(); + prepare_pattern_raw(b"/foo/bar/whatever[0-9]*", &mut dest); end = end - 1; } } diff --git a/crates/squozen/src/prepare_pattern.rs b/crates/squozen/src/prepare_pattern.rs index 77d021d..e8a0188 100644 --- a/crates/squozen/src/prepare_pattern.rs +++ b/crates/squozen/src/prepare_pattern.rs @@ -34,7 +34,7 @@ pub fn prepare_pattern(name: &[u8]) -> Vec { } pub fn prepare_pattern_raw(name: &[u8], dest: &mut Vec) { - let mut eol = name.len(); + let eol = name.len(); if eol == 0 { panic!("Library error - This function should never be called with an empty string.") } @@ -42,7 +42,7 @@ pub fn prepare_pattern_raw(name: &[u8], dest: &mut Vec) { // After this point, eol always points to the index from where we want to // stop, not to the character beyond that. - eol = hunt(name, eol - 1, 0, |&c| c != b'*' && c != b'?'); + let mut eol = hunt(name, eol - 1, 0, |&c| c != b'*' && c != b'?'); if name[eol] == b']' { eol = hunt(&name, eol - 1, 0, |&c| c == b'['); eol = if eol > 0 { eol - 1 } else { 0 }