mirror of
https://codeberg.org/icewind/php-literal-parser.git
synced 2026-06-03 18:44:07 +02:00
format
This commit is contained in:
parent
ecbaf4c336
commit
f96b81aa3a
5 changed files with 28 additions and 17 deletions
|
|
@ -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);
|
||||
|
|
@ -10,5 +10,5 @@
|
|||
inputs.flakelight.follows = "flakelight";
|
||||
};
|
||||
};
|
||||
outputs = { mill-scale, ... }: mill-scale ./. {};
|
||||
outputs = { mill-scale, ... }: mill-scale ./. { };
|
||||
}
|
||||
|
|
@ -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> {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue