@@ -72,6 +72,7 @@ extern crate phf_generator;
72
72
extern crate phf_shared;
73
73
extern crate string_cache_shared as shared;
74
74
#[ macro_use] extern crate quote;
75
+ extern crate proc_macro2;
75
76
76
77
use std:: collections:: HashSet ;
77
78
use std:: fs:: File ;
@@ -169,7 +170,7 @@ impl AtomType {
169
170
pub fn write_to < W > ( & mut self , mut destination : W ) -> io:: Result < ( ) > where W : Write {
170
171
destination. write_all (
171
172
self . to_tokens ( )
172
- . as_str ( )
173
+ . to_string ( )
173
174
// Insert some newlines to make the generated code slightly easier to read.
174
175
. replace ( " [ \" " , "[\n \" " )
175
176
. replace ( "\" , " , "\" ,\n " )
@@ -187,9 +188,18 @@ impl AtomType {
187
188
let atoms: Vec < & str > = self . atoms . iter ( ) . map ( |s| & * * s) . collect ( ) ;
188
189
let hash_state = phf_generator:: generate_hash ( & atoms) ;
189
190
let phf_generator:: HashState { key, disps, map } = hash_state;
191
+ let ( disps0, disps1) : ( Vec < _ > , Vec < _ > ) = disps. into_iter ( ) . unzip ( ) ;
190
192
let atoms: Vec < & str > = map. iter ( ) . map ( |& idx| atoms[ idx] ) . collect ( ) ;
193
+ let atoms_ref = & atoms;
191
194
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
+ } ) ;
193
203
194
204
let hashes: Vec < u32 > =
195
205
atoms. iter ( ) . map ( |string| {
@@ -214,10 +224,11 @@ impl AtomType {
214
224
Some ( ref doc) => quote ! ( #[ doc = #doc] ) ,
215
225
None => quote ! ( )
216
226
} ;
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 ( ) ) ;
221
232
222
233
quote ! {
223
234
#atom_doc
@@ -228,9 +239,9 @@ impl AtomType {
228
239
fn get( ) -> & ' static :: string_cache:: PhfStrSet {
229
240
static SET : :: string_cache:: PhfStrSet = :: string_cache:: PhfStrSet {
230
241
key: #key,
231
- disps: & #disps ,
232
- atoms: & #atoms ,
233
- hashes: & # hashes
242
+ disps: & [ # ( ( #disps0 , #disps1 ) ) , * ] ,
243
+ atoms: & [ # ( #atoms_ref ) , * ] ,
244
+ hashes: & [ # ( # hashes) , * ]
234
245
} ;
235
246
& SET
236
247
}
@@ -242,7 +253,7 @@ impl AtomType {
242
253
#[ macro_export]
243
254
macro_rules! #macro_name {
244
255
#(
245
- ( #atoms ) => {
256
+ ( #atoms_ref ) => {
246
257
$crate :: #path {
247
258
unsafe_data: #data,
248
259
phantom: :: std:: marker:: PhantomData ,
0 commit comments