Compare commits
No commits in common. "a6d4fda5823c1766343e96109dad89c1e84cab2e" and "2eab17934cadac61f5c26564c181e8676c25f219" have entirely different histories.
a6d4fda582
...
2eab17934c
|
@ -1,13 +1,11 @@
|
||||||
use squozen::prepare_pattern::prepare_pattern_raw;
|
use squozen::prepare_pattern::prepare_pattern;
|
||||||
|
|
||||||
const COUNT: usize = 5 * 1000 * 1000 * 100;
|
const COUNT: usize = 5 * 1000 * 1000 * 100;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut end = COUNT;
|
let mut end = COUNT;
|
||||||
let mut dest = Vec::<u8>::with_capacity(100);
|
|
||||||
while end > 0 {
|
while end > 0 {
|
||||||
dest.clear();
|
let _g = prepare_pattern(b"/foo/bar/whatever[0-9]*");
|
||||||
prepare_pattern_raw(b"/foo/bar/whatever[0-9]*", &mut dest);
|
|
||||||
end = end - 1;
|
end = end - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "patprep.h"
|
#include "patprep.h"
|
||||||
|
|
||||||
const int count = 5 * 1000 * 1000 * 100;
|
const int count = 5 * 1000 * 1000 * 1000;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
for (int i = 0; i <= count; i++) {
|
for (int i = 0; i <= count; i++) {
|
||||||
|
|
|
@ -28,13 +28,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prepare_pattern(name: &[u8]) -> Vec<u8> {
|
pub fn prepare_pattern(name: &[u8]) -> Vec<u8> {
|
||||||
let mut dest = Vec::with_capacity(116);
|
let mut eol = name.len();
|
||||||
prepare_pattern_raw(name, &mut dest);
|
|
||||||
dest
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn prepare_pattern_raw(name: &[u8], dest: &mut Vec<u8>) {
|
|
||||||
let eol = name.len();
|
|
||||||
if eol == 0 {
|
if eol == 0 {
|
||||||
panic!("Library error - This function should never be called with an empty string.")
|
panic!("Library error - This function should never be called with an empty string.")
|
||||||
}
|
}
|
||||||
|
@ -42,19 +36,17 @@ 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
|
// After this point, eol always points to the index from where we want to
|
||||||
// stop, not to the character beyond that.
|
// stop, not to the character beyond that.
|
||||||
|
|
||||||
let mut eol = hunt(name, eol - 1, 0, |&c| c != b'*' && c != b'?');
|
eol = hunt(name, eol - 1, 0, |&c| c != b'*' && c != b'?');
|
||||||
if name[eol] == b']' {
|
if name[eol] == b']' {
|
||||||
eol = hunt(&name, eol - 1, 0, |&c| c == b'[');
|
eol = hunt(&name, eol - 1, 0, |&c| c == b'[');
|
||||||
eol = if eol > 0 { eol - 1 } else { 0 }
|
eol = if eol > 0 { eol - 1 } else { 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
if eol == 0 {
|
if eol == 0 {
|
||||||
if GLOBCHARS.contains(&name[0]) {
|
return if GLOBCHARS.contains(&name[0]) {
|
||||||
dest.push(b'/');
|
vec![b'/']
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
dest.push(name[0]);
|
vec![name[0]]
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,9 +57,9 @@ pub fn prepare_pattern_raw(name: &[u8], dest: &mut Vec<u8>) {
|
||||||
start
|
start
|
||||||
};
|
};
|
||||||
if start > eol {
|
if start > eol {
|
||||||
dest.push(b'/');
|
vec![b'/']
|
||||||
} else {
|
} else {
|
||||||
dest.extend_from_slice(&name[start..eol + 1]);
|
name[start..eol + 1].to_vec()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue