This commit is contained in:
Robin Appelman 2024-11-05 15:50:53 +01:00
commit f96b81aa3a
5 changed files with 28 additions and 17 deletions

View file

@ -1,12 +1,15 @@
use php_literal_parser::{from_str, Value};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use php_literal_parser::{from_str, Value};
fn perf_parse_int_basic(b: &mut Criterion) {
let input = "12345676";
b.bench_function("parse int", |b| {
b.iter(|| {
assert_eq!(black_box(from_str::<Value>(black_box(input)).unwrap()), 12345676);
assert_eq!(
black_box(from_str::<Value>(black_box(input)).unwrap()),
12345676
);
});
});
}
@ -14,7 +17,7 @@ fn perf_parse_int_basic(b: &mut Criterion) {
fn perf_str_double_basic(b: &mut Criterion) {
let input = r#""aut dolores excepturi rerum est velit ad natus eveniet quo tenetur et fugiat sit velit ipsam nesciunt sint et architecto""#;
b.bench_function("parse double quote string without escapes",|b| {
b.bench_function("parse double quote string without escapes", |b| {
b.iter(|| {
assert!(black_box(from_str::<Value>(black_box(input)).unwrap()).is_string());
});
@ -46,10 +49,19 @@ fn perf_str_single_escape(b: &mut Criterion) {
b.bench_function("parse single quote escaped string", |b| {
b.iter(|| {
assert!(black_box(from_str::<Value>(black_box(input)).unwrap().is_string()));
assert!(black_box(
from_str::<Value>(black_box(input)).unwrap().is_string()
));
});
});
}
criterion_group!(benches, perf_str_single_escape, perf_str_single_basic, perf_str_double_escape, perf_str_double_basic, perf_parse_int_basic);
criterion_group!(
benches,
perf_str_single_escape,
perf_str_single_basic,
perf_str_double_escape,
perf_str_double_basic,
perf_parse_int_basic
);
criterion_main!(benches);

View file

@ -10,5 +10,5 @@
inputs.flakelight.follows = "flakelight";
};
};
outputs = { mill-scale, ... }: mill-scale ./. {};
outputs = { mill-scale, ... }: mill-scale ./. { };
}

View file

@ -297,10 +297,7 @@ impl<'source> ExpectToken<'source> for SpannedToken<'source> {
}
fn map_span(span: &Span) -> SourceSpan {
SourceSpan::new(
SourceOffset::from(span.start),
span.end - span.start,
)
SourceSpan::new(SourceOffset::from(span.start), span.end - span.start)
}
pub trait ResultExt<T> {

View file

@ -34,7 +34,7 @@ impl UnescapeState {
Some(c) => {
self.push_char(c);
Ok(())
},
}
None => Err(UnescapeError),
}
}
@ -205,8 +205,10 @@ impl<'a> PeekableBytes<'a> {
pub fn is_array_key_numeric(string: &str) -> bool {
let mut bytes = string.bytes();
if !matches!((bytes.next(), string.len()), (Some(b'-'), _) | (Some(b'0'..=b'9'), 1) | (Some(b'1'..=b'9'), _))
{
if !matches!(
(bytes.next(), string.len()),
(Some(b'-'), _) | (Some(b'0'..=b'9'), 1) | (Some(b'1'..=b'9'), _)
) {
return false;
}