Skip to content

Commit

Permalink
Combine Map's Hash into one impl
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jun 25, 2024
1 parent 5e7bedc commit 51d94eb
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,20 +370,19 @@ impl PartialEq for Map<String, Value> {

impl Eq for Map<String, Value> {}

#[cfg(not(feature = "preserve_order"))]
impl Hash for Map<String, Value> {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
self.map.hash(state);
}
}
#[cfg(not(feature = "preserve_order"))]
{
self.map.hash(state);
}

#[cfg(feature = "preserve_order")]
impl Hash for Map<String, Value> {
fn hash<H: Hasher>(&self, state: &mut H) {
let mut kv = Vec::from_iter(&self.map);
kv.sort_unstable_by(|a, b| a.0.cmp(b.0));
kv.hash(state);
#[cfg(feature = "preserve_order")]
{
let mut kv = Vec::from_iter(&self.map);
kv.sort_unstable_by(|a, b| a.0.cmp(b.0));
kv.hash(state);
}
}
}

Expand Down

0 comments on commit 51d94eb

Please sign in to comment.