Minor re-arrangement for compatibiility.

This commit is contained in:
Elf M. Sternberg 2022-11-13 12:40:39 -08:00
parent 40811151ab
commit a6d4fda582
2 changed files with 6 additions and 4 deletions

View File

@ -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::<u8>::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;
}
}

View File

@ -34,7 +34,7 @@ pub fn prepare_pattern(name: &[u8]) -> Vec<u8> {
}
pub fn prepare_pattern_raw(name: &[u8], dest: &mut Vec<u8>) {
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<u8>) {
// 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 }