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
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ default = []
simd = ["toml_parse/simd"]
unsafe = ["toml_parse/unsafe", "toml_edit/unsafe"]
preserve_order = ["toml_old/preserve_order", "toml/preserve_order"]
fast_hash = ["toml/fast_hash"]

[dependencies]
serde = { version = "1.0.197", features = ["derive"] }
Expand Down
2 changes: 2 additions & 0 deletions crates/toml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ std = ["indexmap?/std"]
parse = ["dep:toml_parse", "dep:winnow"]
display = ["std", "dep:toml_edit", "toml_edit?/display"]
unsafe = ["toml_parse?/unsafe"]
fast_hash = ["preserve_order", "dep:foldhash"]
debug = ["std", "toml_parse?/debug", "dep:anstream", "dep:anstyle"]

# Provide a method disable_recursion_limit to parse arbitrarily deep structures
Expand All @@ -57,6 +58,7 @@ anstyle = { version = "1.0.8", optional = true }
toml_edit = { version = "0.22.27", path = "../toml_edit", default-features = false, features = ["serde"], optional = true }
toml_datetime = { version = "0.6.11", path = "../toml_datetime", default-features = false, features = ["serde", "alloc"] }
serde_spanned = { version = "0.6.9", path = "../serde_spanned", default-features = false, features = ["serde", "alloc"] }
foldhash = { version = "0.1.5", default-features = false, optional = true }

[dev-dependencies]
serde = { version = "1.0.199", features = ["derive"] }
Expand Down
30 changes: 15 additions & 15 deletions crates/toml/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ pub struct Map<K, V> {

#[cfg(not(feature = "preserve_order"))]
type MapImpl<K, V> = BTreeMap<K, V>;
#[cfg(all(feature = "preserve_order", not(feature = "fast_hash")))]
type RandomState = std::collections::hash_map::RandomState;
#[cfg(all(feature = "preserve_order", feature = "fast_hash"))]
type RandomState = foldhash::fast::RandomState;
#[cfg(feature = "preserve_order")]
type MapImpl<K, V> = IndexMap<K, V>;
type MapImpl<K, V> = IndexMap<K, V, RandomState>;

impl<K, V> Map<K, V>
where
Expand All @@ -51,6 +55,9 @@ where
#[inline]
pub fn new() -> Self {
Map {
#[cfg(feature = "preserve_order")]
map: MapImpl::with_hasher(RandomState::default()),
#[cfg(not(feature = "preserve_order"))]
map: MapImpl::new(),
dotted: false,
implicit: false,
Expand All @@ -64,20 +71,15 @@ where
pub fn with_capacity(capacity: usize) -> Self {
// does not support with_capacity
let _ = capacity;
Map {
map: BTreeMap::new(),
dotted: false,
implicit: false,
inline: false,
}
Self::new()
}

#[cfg(feature = "preserve_order")]
/// Makes a new empty Map with the given initial capacity.
#[inline]
pub fn with_capacity(capacity: usize) -> Self {
Map {
map: IndexMap::with_capacity(capacity),
map: IndexMap::with_capacity_and_hasher(capacity, RandomState::default()),
dotted: false,
implicit: false,
inline: false,
Expand Down Expand Up @@ -298,15 +300,13 @@ where
}
}

impl<K, V> Default for Map<K, V> {
impl<K, V> Default for Map<K, V>
where
K: Ord + Hash,
{
#[inline]
fn default() -> Self {
Map {
map: MapImpl::new(),
dotted: false,
implicit: false,
inline: false,
}
Self::new()
}
}

Expand Down
Loading