From d6fa1a069ff9a2d3976c3d674a20c5f12bf10b80 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 12 Jul 2023 10:56:40 -0500 Subject: [PATCH] chore(bench): Update winnow to 0.5 --- Cargo.toml | 2 +- benches/json.rs | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4d5a81b7..07563dc5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,7 +72,7 @@ unicode-ident = "1.0.9" ariadne = "0.2" pom = "3.2" nom = "7.1" -winnow = "0.4.9" +winnow = "0.5.0" serde_json = { version = "1.0", features = ["preserve_order"] } ciborium = { version = "0.2" } criterion = "0.4.0" diff --git a/benches/json.rs b/benches/json.rs index 3325f842..e63ead9d 100644 --- a/benches/json.rs +++ b/benches/json.rs @@ -30,7 +30,12 @@ fn bench_json(c: &mut Criterion) { }); c.bench_function("json_winnow", { - move |b| b.iter(|| black_box(winnow::json(black_box(JSON)).unwrap())) + move |b| { + b.iter(|| { + let mut input = black_box(JSON); + black_box(winnow::json(&mut input).unwrap()) + }) + } }); c.bench_function("json_chumsky_zero_copy", { @@ -359,11 +364,11 @@ mod winnow { use super::JsonZero; use std::str; - fn space<'a, E: ParserError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], &'a [u8], E> { + fn space<'a, E: ParserError<&'a [u8]>>(i: &mut &'a [u8]) -> PResult<&'a [u8], E> { take_while(0.., [b' ', b'\t', b'\r', b'\n']).parse_next(i) } - fn number<'a, E: ParserError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], f64, E> { + fn number<'a, E: ParserError<&'a [u8]>>(i: &mut &'a [u8]) -> PResult { ( opt('-'), alt(((one_of(b'1'..=b'9'), digit0).void(), one_of('0').void())), @@ -379,7 +384,7 @@ mod winnow { .parse_next(i) } - fn string<'a, E: ParserError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], &'a [u8], E> { + fn string<'a, E: ParserError<&'a [u8]>>(i: &mut &'a [u8]) -> PResult<&'a [u8], E> { preceded( '"', cut_err(terminated( @@ -394,7 +399,7 @@ mod winnow { .parse_next(i) } - fn array<'a, E: ParserError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], Vec, E> { + fn array<'a, E: ParserError<&'a [u8]>>(i: &mut &'a [u8]) -> PResult>, E> { preceded( '[', cut_err(terminated( @@ -406,8 +411,8 @@ mod winnow { } fn member<'a, E: ParserError<&'a [u8]>>( - i: &'a [u8], - ) -> IResult<&'a [u8], (&'a [u8], JsonZero), E> { + i: &mut &'a [u8], + ) -> PResult<(&'a [u8], JsonZero<'a>), E> { separated_pair( preceded(space, string), cut_err(preceded(space, ':')), @@ -417,8 +422,8 @@ mod winnow { } fn object<'a, E: ParserError<&'a [u8]>>( - i: &'a [u8], - ) -> IResult<&'a [u8], Vec<(&'a [u8], JsonZero)>, E> { + i: &mut &'a [u8], + ) -> PResult)>, E> { preceded( '{', cut_err(terminated( @@ -429,7 +434,7 @@ mod winnow { .parse_next(i) } - fn value<'a, E: ParserError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], JsonZero, E> { + fn value<'a, E: ParserError<&'a [u8]>>(i: &mut &'a [u8]) -> PResult, E> { preceded( space, dispatch!(peek(any); @@ -446,11 +451,11 @@ mod winnow { .parse_next(i) } - fn root<'a, E: ParserError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], JsonZero, E> { + fn root<'a, E: ParserError<&'a [u8]>>(i: &mut &'a [u8]) -> PResult, E> { terminated(value, space).parse_next(i) } - pub fn json<'a>(i: &'a [u8]) -> IResult<&'a [u8], JsonZero, InputError<&'a [u8]>> { + pub fn json<'a>(i: &mut &'a [u8]) -> PResult, InputError<&'a [u8]>> { root.parse_next(i) } }