Skip to content

Commit 89e0ef8

Browse files
author
bors-servo
authored
Auto merge of #203 - hcpl:update-deps, r=SimonSapin
Update dependencies <!-- 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/203) <!-- Reviewable:end -->
2 parents 239c74c + f392c9b commit 89e0ef8

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "string_cache"
4-
version = "0.7.1" # Also update README.md when making a semver-breaking change
4+
version = "0.7.2" # Also update README.md when making a semver-breaking change
55
authors = [ "The Servo Project Developers" ]
66
description = "A string interning library for Rust, developed as part of the Servo project."
77
license = "MIT / Apache-2.0"
@@ -36,7 +36,7 @@ debug_unreachable = "0.1.1"
3636
string_cache_shared = {path = "./shared", version = "0.3"}
3737

3838
[dev-dependencies]
39-
rand = "0.3"
39+
rand = "0.4"
4040

4141
[build-dependencies]
4242
string_cache_codegen = { version = "0.4", path = "./string-cache-codegen" }

src/atom.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use phf_shared;
1313
use serde::{Deserialize, Deserializer, Serialize, Serializer};
1414

15-
#[allow(unused_imports)] use std::ascii::AsciiExt;
1615
use std::borrow::Cow;
1716
use std::cmp::Ordering::{self, Equal};
1817
use std::fmt;

string-cache-codegen/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "string_cache_codegen"
4-
version = "0.4.0" # Also update ../README.md when making a semver-breaking change
4+
version = "0.4.1" # Also update ../README.md when making a semver-breaking change
55
authors = [ "The Servo Project Developers" ]
66
description = "A codegen library for string-cache, developed as part of the Servo project."
77
license = "MIT / Apache-2.0"
@@ -16,4 +16,5 @@ path = "lib.rs"
1616
string_cache_shared = {path = "../shared", version = "0.3"}
1717
phf_generator = "0.7.15"
1818
phf_shared = "0.7.4"
19-
quote = "0.3.9"
19+
proc-macro2 = "0.3.1"
20+
quote = "0.5.1"

string-cache-codegen/lib.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ extern crate phf_generator;
7272
extern crate phf_shared;
7373
extern crate string_cache_shared as shared;
7474
#[macro_use] extern crate quote;
75+
extern crate proc_macro2;
7576

7677
use std::collections::HashSet;
7778
use std::fs::File;
@@ -169,7 +170,7 @@ impl AtomType {
169170
pub fn write_to<W>(&mut self, mut destination: W) -> io::Result<()> where W: Write {
170171
destination.write_all(
171172
self.to_tokens()
172-
.as_str()
173+
.to_string()
173174
// Insert some newlines to make the generated code slightly easier to read.
174175
.replace(" [ \"", "[\n\"")
175176
.replace("\" , ", "\",\n")
@@ -187,9 +188,18 @@ impl AtomType {
187188
let atoms: Vec<&str> = self.atoms.iter().map(|s| &**s).collect();
188189
let hash_state = phf_generator::generate_hash(&atoms);
189190
let phf_generator::HashState { key, disps, map } = hash_state;
191+
let (disps0, disps1): (Vec<_>, Vec<_>) = disps.into_iter().unzip();
190192
let atoms: Vec<&str> = map.iter().map(|&idx| atoms[idx]).collect();
193+
let atoms_ref = &atoms;
191194
let empty_string_index = atoms.iter().position(|s| s.is_empty()).unwrap() as u32;
192-
let data = (0..atoms.len()).map(|i| quote::Hex(shared::pack_static(i as u32)));
195+
let data = (0..atoms.len()).map(|i| {
196+
format!("0x{:X}u64", shared::pack_static(i as u32))
197+
.parse::<proc_macro2::TokenStream>()
198+
.unwrap()
199+
.into_iter()
200+
.next()
201+
.unwrap()
202+
});
193203

194204
let hashes: Vec<u32> =
195205
atoms.iter().map(|string| {
@@ -214,10 +224,11 @@ impl AtomType {
214224
Some(ref doc) => quote!(#[doc = #doc]),
215225
None => quote!()
216226
};
217-
let static_set_name = quote::Ident::from(format!("{}StaticSet", type_name));
218-
let type_name = quote::Ident::from(type_name);
219-
let macro_name = quote::Ident::from(&*self.macro_name);
220-
let path = iter::repeat(quote::Ident::from(&*self.path));
227+
let new_term = |string: &str| proc_macro2::Term::new(string, proc_macro2::Span::call_site());
228+
let static_set_name = new_term(&format!("{}StaticSet", type_name));
229+
let type_name = new_term(type_name);
230+
let macro_name = new_term(&*self.macro_name);
231+
let path = iter::repeat(self.path.parse::<proc_macro2::TokenStream>().unwrap());
221232

222233
quote! {
223234
#atom_doc
@@ -228,9 +239,9 @@ impl AtomType {
228239
fn get() -> &'static ::string_cache::PhfStrSet {
229240
static SET: ::string_cache::PhfStrSet = ::string_cache::PhfStrSet {
230241
key: #key,
231-
disps: &#disps,
232-
atoms: &#atoms,
233-
hashes: &#hashes
242+
disps: &[#((#disps0, #disps1)),*],
243+
atoms: &[#(#atoms_ref),*],
244+
hashes: &[#(#hashes),*]
234245
};
235246
&SET
236247
}
@@ -242,7 +253,7 @@ impl AtomType {
242253
#[macro_export]
243254
macro_rules! #macro_name {
244255
#(
245-
(#atoms) => {
256+
(#atoms_ref) => {
246257
$crate::#path {
247258
unsafe_data: #data,
248259
phantom: ::std::marker::PhantomData,

0 commit comments

Comments
 (0)