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. |
Manishearth
left a comment
There was a problem hiding this comment.
Overall lgtm. What's the plan for namespaces?
build.rs
Outdated
| slice | ||
| string_cache_codegen::AtomType::new("atom::tests::TestAtom", "test_atom!") | ||
| .atoms(&[ | ||
| "a", "b", "address", "area", "body", "font-weight", "br","html", "head", "id", |
| mod shared; | ||
|
|
||
| use string_cache::Atom; | ||
| use string_cache::DefaultAtom; |
There was a problem hiding this comment.
we should probably use DefaultAtom as Atom consistently across the examples
| } | ||
| 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.
why not continue to use get_index_or_hash()?
There was a problem hiding this comment.
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_codegencrate 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