-
Notifications
You must be signed in to change notification settings - Fork 79
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
Make Atom generic over the set of static strings #178
Conversation
selectors doesn’t use it anymore.
Prepare for adding a type parameter that derive would require bounds on.
We’re about to introduce a trait name StaticAtomSet.
fe9d8f7
to
d5b1001
Compare
Oh boy, I'm excited! No worries about taking so long, I understand it can take a while for the stars to align and get time. Some thoughts:
I'll actually try it out a bit later. |
Oh, good point about using different hash functions in the one dynamic atom hash table. I had not thought of that. So now I'm not sure it's the right thing to do :) I'll think on it a bit more. |
b54d9d9
to
0a81c4d
Compare
After chatting with @nox I think we’re gonna keep things as-is now regarding hashing. We can always change it later (without even breaking any public API). Regarding testing, the I’ve pushed another commit that extends the README with some usage examples. |
Ok, I've tried it out and it seems to work fine for me and the examples look good to me. It's a little sad it can't use phf generated sets directly, but I can see that's tricky given the desire to want to have direct access to the hash value without recomputing. Maybe someday. Nothing else from me I don't think 👍 |
I didn’t make it expose any public functionality to keep small the set of API we’ll need to maintain and because I didn’t see a use for it, but it could. What would you like to do with the set, and why? |
It's more a general feeling that it'd be nice to use phf_codegen (and therefore phf_sets) directly rather than recreating them. As you note, given that parts of the api are not considered public it'd be a bit risky to depend on them for functionality. Perhaps the long term solution is to negotiate with phf to expose the bits that would be useful for string-cache, but I wouldn't want that to come before merging this PR. |
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.
Overall lgtm. What's the plan for namespaces?
slice | ||
string_cache_codegen::AtomType::new("atom::tests::TestAtom", "test_atom!") | ||
.atoms(&[ | ||
"a", "b", "address", "area", "body", "font-weight", "br","html", "head", "id", |
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.
nit: space after br
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.
Fixed.
#[allow(dead_code)] | ||
mod shared; | ||
|
||
use string_cache::Atom; | ||
use string_cache::DefaultAtom; |
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.
we should probably use DefaultAtom as Atom
consistently across the examples
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.
Done.
} | ||
fn from(string_to_add: Cow<'a, str>) -> Self { | ||
let static_set = Static::get(); | ||
let hash = phf_shared::hash(&*string_to_add, static_set.key); |
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.
why not continue to use get_index_or_hash()
?
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.
It would have to be a method of a public trait, and thus changing it (if we need to in the future) would be a breaking change.
It’s going into various atom types in html5ever and Servo.
ce286ac
to
4528d77
Compare
The plan for namespaces is to have them in a new
|
r=me , unless @nox wants to have a look |
@bors-servo r=Manishearth |
📌 Commit 4528d77 has been approved by |
⚡ Test exempted - status |
Make Atom generic over the set of static strings The new `string_cache_codegen` crate is intended to be used by downstream users in their build scripts. Provided a list of static strings, it generates code that defines: - A type alias for `Atom<_>` with the type parameter set, - A macro like the former `atom!` macro. Based on #136, original work by @aidanhs. Fixes #22, fixes #136, closes #83. r? @nox <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/string-cache/178) <!-- Reviewable:end -->
🎆 |
The new
string_cache_codegen
crate is intended to be used by downstream users in their build scripts. Provided a list of static strings, it generates code that defines:Atom<_>
with the type parameter set,atom!
macro.Based on #136, original work by @aidanhs.
Fixes #22, fixes #136, closes #83.
r? @nox
This change is