From bbbdcbc3b8167cc65eb292b86c3c00c13738700b Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Mon, 9 Sep 2024 16:10:47 +0100 Subject: [PATCH] try new jiter `LazyIndexMap` implementation --- Cargo.lock | 75 ++++++++++++++++++++++++----------------- Cargo.toml | 2 +- src/input/input_json.rs | 5 ++- src/lib.rs | 2 +- src/validators/json.rs | 2 +- 5 files changed, 50 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7acd7801..510c79fe6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,9 +50,12 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.101" +version = "1.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac367972e516d45567c7eafc73d24e1c193dcf200a8d94e9db7b3d38b349572d" +checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" +dependencies = [ + "shlex", +] [[package]] name = "cfg-if" @@ -189,7 +192,7 @@ dependencies = [ "icu_normalizer_data", "icu_properties", "icu_provider", - "smallvec", + "smallvec 1.13.2", "utf16_iter", "utf8_iter", "write16", @@ -269,15 +272,15 @@ checksum = "bd69211b9b519e98303c015e21a007e293db403b6c85b9b124e133d25e242cdd" dependencies = [ "icu_normalizer", "icu_properties", - "smallvec", + "smallvec 1.13.2", "utf8_iter", ] [[package]] name = "indexmap" -version = "2.2.6" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown", @@ -298,17 +301,17 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jiter" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e23549143ef50eddffd46ba8cd0229b0a4500aef7518cf2eb0f41c9a09d22b" +source = "git+https://github.com/pydantic/jiter?branch=invariant-lifetimes#007b28c7bb644c91da36ef343898db4a0e9c51c5" dependencies = [ "ahash", "bitvec", + "indexmap", "lexical-parse-float", "num-bigint", "num-traits", "pyo3", "pyo3-build-config", - "smallvec", + "smallvec 2.0.0-alpha.7", ] [[package]] @@ -343,9 +346,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.155" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "litemap" @@ -410,9 +413,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "portable-atomic" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" +checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" [[package]] name = "proc-macro2" @@ -440,7 +443,7 @@ dependencies = [ "regex", "serde", "serde_json", - "smallvec", + "smallvec 1.13.2", "speedate", "strum", "strum_macros", @@ -525,9 +528,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -581,18 +584,18 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "serde" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", @@ -612,12 +615,24 @@ dependencies = [ "serde", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "smallvec" version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "smallvec" +version = "2.0.0-alpha.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6a96cb564e12be8458b004bd829787ebe887de197d94516d2ba5a2a32235a0c" + [[package]] name = "speedate" version = "0.14.4" @@ -664,9 +679,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.68" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -692,9 +707,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "target-lexicon" -version = "0.12.14" +version = "0.12.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "tinystr" @@ -708,9 +723,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" dependencies = [ "tinyvec_macros", ] @@ -836,18 +851,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 8cc5be11d..30a6e17c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,7 @@ base64 = "0.22.1" num-bigint = "0.4.6" python3-dll-a = "0.2.10" uuid = "1.10.0" -jiter = { version = "0.5", features = ["python"] } +jiter = { git = "https://github.com/pydantic/jiter", branch = "invariant-lifetimes", features = ["python"] } hex = "0.4.3" [lib] diff --git a/src/input/input_json.rs b/src/input/input_json.rs index 7c77928d0..0a8e73194 100644 --- a/src/input/input_json.rs +++ b/src/input/input_json.rs @@ -3,7 +3,6 @@ use std::borrow::Cow; use jiter::{JsonArray, JsonObject, JsonValue, LazyIndexMap}; use pyo3::prelude::*; use pyo3::types::{PyDict, PyList, PyString}; -use smallvec::SmallVec; use speedate::MicrosecondsPrecisionOverflowBehavior; use strum::EnumMessage; @@ -522,7 +521,7 @@ impl<'a, 'py, 'data> ValidatedList<'py> for &'a JsonArray<'data> { type Item = &'a JsonValue<'data>; fn len(&self) -> Option { - Some(SmallVec::len(self)) + Some((**self).len()) } fn iterate(self, consumer: impl ConsumeIterator, Output = R>) -> ValResult { Ok(consumer.consume_iterator(self.iter().map(Ok))) @@ -536,7 +535,7 @@ impl<'a, 'data> ValidatedTuple<'_> for &'a JsonArray<'data> { type Item = &'a JsonValue<'data>; fn len(&self) -> Option { - Some(SmallVec::len(self)) + Some((**self).len()) } fn iterate(self, consumer: impl ConsumeIterator, Output = R>) -> ValResult { Ok(consumer.consume_iterator(self.iter().map(Ok))) diff --git a/src/lib.rs b/src/lib.rs index d1e042863..71f8a426d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,7 +61,7 @@ pub fn from_json<'py>( cache_mode: cache_strings, partial_mode: allow_partial, catch_duplicate_keys: false, - lossless_floats: false, + float_mode: jiter::FloatMode::Float, }; parse_builder .python_parse(py, json_bytes) diff --git a/src/validators/json.rs b/src/validators/json.rs index f86cc4624..01f3d2ef4 100644 --- a/src/validators/json.rs +++ b/src/validators/json.rs @@ -71,7 +71,7 @@ impl Validator for JsonValidator { cache_mode: state.cache_str(), partial_mode: PartialMode::Off, catch_duplicate_keys: false, - lossless_floats: false, + float_mode: jiter::FloatMode::Float, }; let obj = parse_builder .python_parse(py, json_bytes)