diff --git a/Cargo.lock b/Cargo.lock index 047fb4886..18e99107f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,17 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "0.7.18" @@ -47,6 +58,17 @@ dependencies = [ "syn", ] +[[package]] +name = "getrandom" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "hashbrown" version = "0.11.2" @@ -177,6 +199,7 @@ dependencies = [ name = "pydantic-core" version = "0.0.1" dependencies = [ + "ahash", "enum_dispatch", "indexmap", "mimalloc", @@ -393,6 +416,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 076ab0c3d..adb8bf1f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ serde = "1.0.137" indexmap = "1.8.1" mimalloc = { version = "0.1.29", default-features = false, optional = true } speedate = "0.4.1" +ahash = "0.7.6" [lib] name = "_pydantic_core" diff --git a/src/validators/literal.rs b/src/validators/literal.rs index 914354c8c..aee203d05 100644 --- a/src/validators/literal.rs +++ b/src/validators/literal.rs @@ -1,8 +1,8 @@ -use std::collections::HashSet; - use pyo3::prelude::*; use pyo3::types::{PyDict, PyList}; +use ahash::AHashSet; + use crate::build_tools::{py_error, SchemaDict}; use crate::errors::{as_internal, context, err_val_error, ErrorKind, ValResult}; use crate::input::Input; @@ -119,13 +119,13 @@ impl Validator for LiteralSingleIntValidator { #[derive(Debug, Clone)] pub struct LiteralMultipleStringsValidator { - expected: HashSet, + expected: AHashSet, repr: String, } impl LiteralMultipleStringsValidator { fn new(expected_list: &PyList) -> Option { - let mut expected: HashSet = HashSet::new(); + let mut expected: AHashSet = AHashSet::new(); let mut repr_args = Vec::new(); for item in expected_list.iter() { if let Ok(str) = item.extract() { @@ -170,13 +170,13 @@ impl Validator for LiteralMultipleStringsValidator { #[derive(Debug, Clone)] pub struct LiteralMultipleIntsValidator { - expected: HashSet, + expected: AHashSet, repr: String, } impl LiteralMultipleIntsValidator { fn new(expected_list: &PyList) -> Option { - let mut expected: HashSet = HashSet::new(); + let mut expected: AHashSet = AHashSet::new(); let mut repr_args = Vec::new(); for item in expected_list.iter() { if let Ok(str) = item.extract() { @@ -221,16 +221,16 @@ impl Validator for LiteralMultipleIntsValidator { #[derive(Debug, Clone)] pub struct LiteralGeneralValidator { - expected_int: HashSet, - expected_str: HashSet, + expected_int: AHashSet, + expected_str: AHashSet, expected_py: Py, repr: String, } impl LiteralGeneralValidator { fn new(expected: &PyList) -> PyResult { - let mut expected_int = HashSet::new(); - let mut expected_str = HashSet::new(); + let mut expected_int = AHashSet::new(); + let mut expected_str = AHashSet::new(); let py = expected.py(); let expected_py = PyList::empty(py); let mut repr_args: Vec = Vec::new(); diff --git a/src/validators/typed_dict.rs b/src/validators/typed_dict.rs index bd1e6712d..6783bba1a 100644 --- a/src/validators/typed_dict.rs +++ b/src/validators/typed_dict.rs @@ -2,7 +2,8 @@ use pyo3::exceptions::{PyAttributeError, PyTypeError}; use pyo3::intern; use pyo3::prelude::*; use pyo3::types::{PyDict, PyFunction, PyList, PySet, PyString}; -use std::collections::HashSet; + +use ahash::AHashSet; use crate::build_tools::{py_error, SchemaDict}; use crate::errors::{ @@ -143,8 +144,8 @@ impl Validator for TypedDictValidator { // we only care about which keys have been used if we're iterating over the object for extra after // the first pass - let mut used_keys: Option> = match self.check_extra { - true => Some(HashSet::with_capacity(self.fields.len())), + let mut used_keys: Option> = match self.check_extra { + true => Some(AHashSet::with_capacity(self.fields.len())), false => None, };