Repository navigation
feat(known-key): add OwnedValue & OwnedObject lookup support to KnownKey - #470
Open
Aditya-9-6 wants to merge 2 commits into
Open
Aditya-9-6 wants to merge 2 commits into
Aditya-9-6 wants to merge 2 commits into
Conversation
Licenser
requested changes
Oct 3, 2026
Licenser
left a comment
Member
There was a problem hiding this comment.
I'm not a fan of adding a bunch off _owned functions that feels like a fairly painful API to use. Would it be possible to make the functions generic over the target instead?
Replace separate _owned functions with KnownKeyTarget and KnownKeyTargetMut traits, making lookup and lookup_mut generic across BorrowedValue, OwnedValue, and map objects. Also generalize map_lookup and map_lookup_mut across any HashMap with ObjectHasher whose key borrows as &str.
Author
|
Great suggestion! I've refactored the API to make \lookup\ and \lookup_mut\ generic over the target using \KnownKeyTarget\ and \KnownKeyTargetMut\ traits (implemented for \BorrowedValue, \OwnedValue, and map objects), and generalized \map_lookup\ and \map_lookup_mut\ across any \HashMap<K, V, ObjectHasher>\ where \K: Borrow. All separate _owned\ methods have been removed, and all unit tests, doctests, and clippy pass cleanly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Currently,
KnownKeyprovides fast O(1) hashed key lookup methods (lookup,map_lookup,lookup_mut,map_lookup_mut) exclusively forBorrowedValueandBorrowedObject.This PR adds complete support for
OwnedValueandOwnedObjecttoKnownKey, allowing applications using owned DOM representations to benefit from pre-computed hash lookups without re-hashing key strings.Proposed Changes
KnownKey::lookup_owned: Fast O(1) lookup on&OwnedValue.KnownKey::map_lookup_owned: Fast O(1) lookup on&owned::Object.KnownKey::lookup_owned_mut: Mutable O(1) lookup on&mut OwnedValue.KnownKey::map_lookup_owned_mut: Mutable O(1) lookup on&mut owned::Object.test_known_key_owned()insrc/known_key.rs.Verification
cargo test --features known-key: All unit tests, integration tests, and doc-tests passed cleanly.cargo clippy --features known-key: Passed with 0 warnings/errors.