-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add no-hash-lookup way to retrieve the default interned value #13035
Conversation
Pull Request Test Coverage Report for Build 10623649976Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
0aee777
to
cb0a25a
Compare
One or more of the following people are relevant to this code:
|
cb0a25a
to
8c4568d
Compare
This makes it possible to do `Interner::get_default()` without any value, in order to retrieve a key pointing to the default allocation without making any hash lookups. While the hashing and equality check of the default allocation is typically very cheap (like the empty slice), acquiring it still generally required a function call, which often needed to be paid frequently.
8c4568d
to
9d5eb98
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is again, very cool.
I don't think it's a problem that the type needs to implement Default
. When Rust has specialization, it'd be neat to have two new
impls that either initialize a default or not, and then constrain the get_default
method to be applicable only for T: Default
, like you mention in the docstring. But T: Default
at the struct-level feels entirely fine to me.
Another API alternative here is to add an implementation of |
I see what you mean. I think having both could be nice, but the explicit method seems like it'd be easier for folks to find, which may result in us seeing less of |
Co-authored-by: Kevin Hartman <[email protected]>
Added the symmetric method in 7cc72b1. |
What was the reason not to impl Otherwise, looks good. |
I didn't think super hard about it, I think my default API position is just to define concrete methods rather than hide new functionality in trait implementations. Thinking more now, I'd say that "the interned key of the default value" is not necessarily the same thing as the "default interned key", but that said: maybe my position on the trait is skewed, because imo integer types shouldn't have a default, and neither should an interner key. Judging by the API choices in both Python and Rust, though, I'm in the minority there (e.g. Python's |
I think in this case, I would actually rather we just have the
Hmm. It's late in the night so I'm probably not picking up on the subtly, but wouldn't that break the premise of us using |
I'm fine to remove it too, just let me know. If you want me to turn it into an actual I'd say that |
I'm not worried either 🙂. But tl;dr, I think you should just remove
What I meant was more that we're locking ourselves out of creating default |
Ok, it's gone again in b96698b. (Fwiw, given none of this Rust stuff is in any way public, I'm not really worried about locking ourselves out of anything - this PR's parent just changed the entire |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for the changes!
Summary
This makes it possible to do
Interner::get_default()
without any value, in order to retrieve a key pointing to the default allocation without making any hash lookups. While the hashing and equality check of the default allocation is typically very cheap (like the empty slice), acquiring it still generally required a function call, which often needed to be paid frequently.Details and comments
Built on top of #13033, so depends on it.