Skip to content

Commit

Permalink
Auto merge of #203 - hcpl:update-deps, r=SimonSapin
Browse files Browse the repository at this point in the history
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 -->
  • Loading branch information
bors-servo authored Apr 10, 2018
2 parents 239c74c + f392c9b commit 89e0ef8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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" }
1 change: 0 additions & 1 deletion src/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions string-cache-codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
31 changes: 21 additions & 10 deletions string-cache-codegen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -169,7 +170,7 @@ impl AtomType {
pub fn write_to<W>(&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")
Expand All @@ -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::<proc_macro2::TokenStream>()
.unwrap()
.into_iter()
.next()
.unwrap()
});

let hashes: Vec<u32> =
atoms.iter().map(|string| {
Expand All @@ -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::<proc_macro2::TokenStream>().unwrap());

quote! {
#atom_doc
Expand All @@ -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
}
Expand All @@ -242,7 +253,7 @@ impl AtomType {
#[macro_export]
macro_rules! #macro_name {
#(
(#atoms) => {
(#atoms_ref) => {
$crate::#path {
unsafe_data: #data,
phantom: ::std::marker::PhantomData,
Expand Down

0 comments on commit 89e0ef8

Please sign in to comment.