Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upMake Atom generic over the set of static strings #178
Conversation
|
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. |
|
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. |
|
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", |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| #[allow(dead_code)] | ||
| mod shared; | ||
|
|
||
| use string_cache::Atom; | ||
| use string_cache::DefaultAtom; |
This comment has been minimized.
This comment has been minimized.
Manishearth
Nov 1, 2016
Member
we should probably use DefaultAtom as Atom consistently across the examples
This comment has been minimized.
This comment has been minimized.
| } | ||
| 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); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
SimonSapin
Nov 1, 2016
Author
Member
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.
|
The plan for namespaces is to have them in a new
|
|
r=me , unless @nox wants to have a look |
|
@bors-servo r=Manishearth |
|
|
|
|
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 -->
|
|
SimonSapin commentedOct 27, 2016
•
edited by larsbergstrom
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