Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
[package]
name = "rtoml"
version = "0.12.0"
version = "0.13.0"
authors = ["Samuel Colvin <s@muelcolvin.com>"]
edition = "2021"
license = "MIT"

[dependencies]
toml = {version = "0.5.9", features = ["preserve_order"]}
toml = {version = "0.5.11", features = ["preserve_order"]}
serde = "1.0.228"
pyo3 = "0.26.0"
ahash = "0.8.12"
nohash-hasher = "0.2.0"

[lib]
name = "_rtoml"
Expand Down
14 changes: 4 additions & 10 deletions src/de.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
use std::collections::HashSet;
use std::fmt;
use std::hash::BuildHasherDefault;
use std::marker::PhantomData;
use std::str::FromStr;

use pyo3::prelude::*;
use pyo3::types::PyDict;
use pyo3::IntoPyObjectExt;

use ahash::RandomState;
use nohash_hasher::NoHashHasher;
use ahash::AHashSet;
use serde::de::{self, DeserializeSeed, Deserializer, MapAccess, SeqAccess, Visitor};
use toml::value::Datetime as TomlDatetime;

use crate::datetime;

pub const DATETIME_MAPPING_KEY: &str = "$__toml_private_datetime";
type BuildNoHashHasher<T> = BuildHasherDefault<NoHashHasher<T>>;
pub type NoHashSet<T> = HashSet<T, BuildNoHashHasher<T>>;

pub struct PyDeserializer<'py> {
py: Python<'py>,
Expand Down Expand Up @@ -116,17 +111,16 @@ impl<'de> Visitor<'de> for PyDeserializer<'_> {
Some((first_key, first_value)) => {
// we use a hashset to check for duplicate keys, but to avoid cloning the keys, we hash manually
// and store that in a no-hash hashset
let hash_builder = RandomState::new();
let mut key_set = NoHashSet::<u64>::with_hasher(BuildHasherDefault::default());
key_set.insert(hash_builder.hash_one(&first_key));
let mut key_set = AHashSet::new();
key_set.insert(first_key.clone());

let dict = PyDict::new(self.py);
dict.set_item(first_key, first_value).map_err(de::Error::custom)?;

while let Some((key, value)) =
map_access.next_entry_seed(PhantomData::<String>, PyDeserializer::new(self.py, self.none_value))?
{
if key_set.insert(hash_builder.hash_one(&key)) {
if key_set.insert(key.clone()) {
dict.set_item(key, value).map_err(de::Error::custom)?;
} else {
return Err(de::Error::custom(format!("duplicate key: `{key}`")));
Expand Down