Skip to content

Better Hash and PartialEq for Keys and AnchoredKeys#277

Merged
robknight merged 1 commit intomainfrom
better_hash_impl
Jun 11, 2025
Merged

Better Hash and PartialEq for Keys and AnchoredKeys#277
robknight merged 1 commit intomainfrom
better_hash_impl

Conversation

@robknight
Copy link
Collaborator

@robknight robknight commented Jun 11, 2025

When adding the original serialization code, I added the Hash and PartialEq traits to AnchoredKey and Key. The default implementation hashes both the hash and name fields of Key together, which is unnecessary - we can hash just the hash field instead. Similarly, PartialEq does not need to compare both fields, it can compare just the hash field. This mirrors how the same traits were implemented for the Value type.

This should make storing Keys/AnchoredKeys in hashmaps/sets slightly more efficient.

@robknight robknight requested a review from ed255 June 11, 2025 05:50
Copy link
Collaborator

@ed255 ed255 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@robknight robknight merged commit 3ea0d5b into main Jun 11, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants