diff --git a/Cargo.toml b/Cargo.toml index 14adf72..95ad89a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "string_cache" -version = "0.7.1" # Also update README.md when making a semver-breaking change +version = "0.7.2" # Also update README.md when making a semver-breaking change authors = [ "The Servo Project Developers" ] description = "A string interning library for Rust, developed as part of the Servo project." license = "MIT / Apache-2.0" @@ -36,7 +36,7 @@ debug_unreachable = "0.1.1" string_cache_shared = {path = "./shared", version = "0.3"} [dev-dependencies] -rand = "0.3" +rand = "0.4" [build-dependencies] string_cache_codegen = { version = "0.4", path = "./string-cache-codegen" } diff --git a/src/atom.rs b/src/atom.rs index c8b2f3c..7a48031 100644 --- a/src/atom.rs +++ b/src/atom.rs @@ -12,7 +12,6 @@ use phf_shared; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -#[allow(unused_imports)] use std::ascii::AsciiExt; use std::borrow::Cow; use std::cmp::Ordering::{self, Equal}; use std::fmt; diff --git a/string-cache-codegen/Cargo.toml b/string-cache-codegen/Cargo.toml index 14b93a6..c11952b 100644 --- a/string-cache-codegen/Cargo.toml +++ b/string-cache-codegen/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "string_cache_codegen" -version = "0.4.0" # Also update ../README.md when making a semver-breaking change +version = "0.4.1" # Also update ../README.md when making a semver-breaking change authors = [ "The Servo Project Developers" ] description = "A codegen library for string-cache, developed as part of the Servo project." license = "MIT / Apache-2.0" @@ -16,4 +16,5 @@ path = "lib.rs" string_cache_shared = {path = "../shared", version = "0.3"} phf_generator = "0.7.15" phf_shared = "0.7.4" -quote = "0.3.9" +proc-macro2 = "0.3.1" +quote = "0.5.1" diff --git a/string-cache-codegen/lib.rs b/string-cache-codegen/lib.rs index e92f8a0..7312bcf 100644 --- a/string-cache-codegen/lib.rs +++ b/string-cache-codegen/lib.rs @@ -72,6 +72,7 @@ extern crate phf_generator; extern crate phf_shared; extern crate string_cache_shared as shared; #[macro_use] extern crate quote; +extern crate proc_macro2; use std::collections::HashSet; use std::fs::File; @@ -169,7 +170,7 @@ impl AtomType { pub fn write_to(&mut self, mut destination: W) -> io::Result<()> where W: Write { destination.write_all( self.to_tokens() - .as_str() + .to_string() // Insert some newlines to make the generated code slightly easier to read. .replace(" [ \"", "[\n\"") .replace("\" , ", "\",\n") @@ -187,9 +188,18 @@ impl AtomType { let atoms: Vec<&str> = self.atoms.iter().map(|s| &**s).collect(); let hash_state = phf_generator::generate_hash(&atoms); let phf_generator::HashState { key, disps, map } = hash_state; + let (disps0, disps1): (Vec<_>, Vec<_>) = disps.into_iter().unzip(); let atoms: Vec<&str> = map.iter().map(|&idx| atoms[idx]).collect(); + let atoms_ref = &atoms; let empty_string_index = atoms.iter().position(|s| s.is_empty()).unwrap() as u32; - let data = (0..atoms.len()).map(|i| quote::Hex(shared::pack_static(i as u32))); + let data = (0..atoms.len()).map(|i| { + format!("0x{:X}u64", shared::pack_static(i as u32)) + .parse::() + .unwrap() + .into_iter() + .next() + .unwrap() + }); let hashes: Vec = atoms.iter().map(|string| { @@ -214,10 +224,11 @@ impl AtomType { Some(ref doc) => quote!(#[doc = #doc]), None => quote!() }; - let static_set_name = quote::Ident::from(format!("{}StaticSet", type_name)); - let type_name = quote::Ident::from(type_name); - let macro_name = quote::Ident::from(&*self.macro_name); - let path = iter::repeat(quote::Ident::from(&*self.path)); + let new_term = |string: &str| proc_macro2::Term::new(string, proc_macro2::Span::call_site()); + let static_set_name = new_term(&format!("{}StaticSet", type_name)); + let type_name = new_term(type_name); + let macro_name = new_term(&*self.macro_name); + let path = iter::repeat(self.path.parse::().unwrap()); quote! { #atom_doc @@ -228,9 +239,9 @@ impl AtomType { fn get() -> &'static ::string_cache::PhfStrSet { static SET: ::string_cache::PhfStrSet = ::string_cache::PhfStrSet { key: #key, - disps: &#disps, - atoms: &#atoms, - hashes: &#hashes + disps: &[#((#disps0, #disps1)),*], + atoms: &[#(#atoms_ref),*], + hashes: &[#(#hashes),*] }; &SET } @@ -242,7 +253,7 @@ impl AtomType { #[macro_export] macro_rules! #macro_name { #( - (#atoms) => { + (#atoms_ref) => { $crate::#path { unsafe_data: #data, phantom: ::std::marker::PhantomData,