Skip to content

Commit

Permalink
replace lexical-core with minimal-lexical
Browse files Browse the repository at this point in the history
minimal-lexical is a smaller library (compile faster), has no
dependencies, and is faster than lexical-core 0.7 (0.8 will have the
same algorithm).

It requires a separate tokenization phase, done manually, but this will
give more flexibility in supporting different syntaxes

This commit removes the "lexical" feature, as there is no need now
tosupport a separate version without the crate
  • Loading branch information
Geal committed Aug 17, 2021
1 parent 6cd562e commit baf5e01
Show file tree
Hide file tree
Showing 8 changed files with 347 additions and 194 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- rust: stable
features: ''
- rust: stable
features: '--features "std lexical"'
features: '--features "std"'
- rust: stable
features: '--no-default-features'
- rust: stable
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: doc
args: --verbose --features "std lexical docsrs"
args: --verbose --features "std docsrs"

fmt:
name: Check formatting
Expand Down
10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,16 @@ include = [
[features]
alloc = []
std = ["alloc", "memchr/use_std"]
default = ["std", "lexical"]
lexical = ["lexical-core"]
default = ["std"]
docsrs = []

[dependencies]
minimal-lexical = "0.1.2"

[dependencies.memchr]
version = "2.0"
default-features = false

[dependencies.lexical-core]
version = "^0.7.5"
optional = true

[dev-dependencies]
criterion = "0.3"
jemallocator = "^0.3"
Expand Down
23 changes: 23 additions & 0 deletions benches/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,35 @@ fn float_str(c: &mut Criterion) {
});
}

use nom::ParseTo;
use nom::Err;
fn std_float(input: &[u8]) -> IResult<&[u8], f64, (&[u8], ErrorKind)> {
match recognize_float(input) {
Err(e) => Err(e),
Ok((i, s)) => match s.parse_to() {
Some(n) => Ok((i, n)),
None => Err(Err::Error((i, ErrorKind::Float))),
},
}
}

fn std_float_bytes(c: &mut Criterion) {
println!(
"std_float_bytes result: {:?}",
std_float(&b"-1.234E-12"[..])
);
c.bench_function("std_float bytes", |b| {
b.iter(|| std_float(&b"-1.234E-12"[..]));
});
}

criterion_group!(
benches,
json_bench,
recognize_float_bytes,
recognize_float_str,
float_bytes,
std_float_bytes,
float_str
);
criterion_main!(benches);
1 change: 1 addition & 0 deletions proptest-regressions/character/complete.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
cc cc9654fa1abddf4d6045e4c4977fea390903ee6e6469630b0bb17fdf69219b6d # shrinks to s = "𑵧"
cc 7dcadb118055527708beb3c5eadd3e14202a8f70e019004c33e9696853691827 # shrinks to s = ""
cc e8af68daccf860a49177b5aab0dfeecea24c7530fec6c88469ca0f820188c6b1 # shrinks to s = "-"
cc c98c899dcd0a9359ddbf246e3a1edddb349e6dd7e1d166637e551e4dcf570db6 # shrinks to s = "+0"
2 changes: 2 additions & 0 deletions proptest-regressions/character/streaming.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
# everyone who runs the test benefits from these saved cases.
cc 82a575ed1f031825e7474bff3702d0c42017471b5ac845bdbdc00c1534dbc4cb # shrinks to s = ""
cc 155f8f4b052941ba58b8b90a5f8fa7da78c04c1a451083a4a89a348c86226904 # shrinks to s = "0"
cc c35a5a751223822dd0a94416d5ca3cc53b4a61cdc4f9422251bc2c72712ed844 # shrinks to s = "-0"
cc 478373182b684c42ce3746ea62d57a35a9c764ef75943e0bb1dc08f88b295581 # shrinks to s = "- "
13 changes: 13 additions & 0 deletions proptest-regressions/number/complete.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc b4267e69b3f62d9bfbc8b9a11d9250a4cc78a2f329841190fd2740b1b3e236d6 # shrinks to s = ""
cc cf51966684042789e64f4b99449551cb227309f9db61f0fdd4266b0b7b572ce4 # shrinks to s = "0"
cc fc0d8df9f3a0ea46ec05ff021be24244fe2533c4b5d75e74a78191148e2d07bb # shrinks to s = "0"
cc 15e795e3c045df60a2fa871336f9bf43ca9036aeda19e8e440b956866b031a65 # shrinks to s = "0e"
cc 20b201c32f3f8314cf32133c3e6a58dd1e4409ae883f7910efa1147ba7c73b6c # shrinks to s = "e"
cc 47f9c093d94bc952a3593a79adc2cafa75c9cca51bee8a77150cfaeb89acbaf7 # shrinks to s = "01"
cc 9d65816e63ee5da410b64aeb5f7d44dbfa7d0773c053380e05bff0beb1bc8d92 # shrinks to s = ".0"
Loading

0 comments on commit baf5e01

Please sign in to comment.