|
1 | 1 | use proc_macro2::{Span, TokenStream};
|
2 | 2 | use quote::{quote, ToTokens};
|
| 3 | +use std::collections::hash_map::DefaultHasher; |
3 | 4 | use std::env;
|
| 5 | +use std::hash::{Hash, Hasher}; |
4 | 6 | use std::path::{Path, PathBuf};
|
5 | 7 | use syn::parse::{Parse, ParseStream, Result as ParseResult};
|
6 | 8 | use syn::punctuated::Punctuated;
|
@@ -134,31 +136,23 @@ fn resolve_template_file(path: &str, template_dirs: &[PathBuf]) -> Option<PathBu
|
134 | 136 | fn filename_hash(path: &Path) -> String {
|
135 | 137 | use std::fmt::Write;
|
136 | 138 |
|
137 |
| - const FNV_PRIME: u64 = 1_099_511_628_211; |
138 |
| - const FNV_OFFSET_BASIS: u64 = 14_695_981_039_346_656_037; |
139 |
| - |
140 |
| - let mut hash = String::with_capacity(16); |
| 139 | + let mut path_with_hash = String::with_capacity(16); |
141 | 140 |
|
142 | 141 | if let Some(n) = path.file_name() {
|
143 | 142 | let mut filename = &*n.to_string_lossy();
|
144 | 143 | if let Some(p) = filename.find('.') {
|
145 | 144 | filename = &filename[..p];
|
146 | 145 | }
|
147 |
| - hash.push_str(filename); |
148 |
| - hash.push('-'); |
149 |
| - } |
150 |
| - |
151 |
| - // calculate 64bit hash |
152 |
| - let mut h = FNV_OFFSET_BASIS; |
153 |
| - for b in (&*path.to_string_lossy()).bytes() { |
154 |
| - h = h.wrapping_mul(FNV_PRIME); |
155 |
| - h ^= b as u64; |
| 146 | + path_with_hash.push_str(filename); |
| 147 | + path_with_hash.push('-'); |
156 | 148 | }
|
157 | 149 |
|
158 |
| - // convert 64bit hash into ascii |
159 |
| - let _ = write!(hash, "{:016x}", h); |
| 150 | + let mut hasher = DefaultHasher::new(); |
| 151 | + path.hash(&mut hasher); |
| 152 | + let hash = hasher.finish(); |
| 153 | + let _ = write!(path_with_hash, "{:016x}", hash); |
160 | 154 |
|
161 |
| - hash |
| 155 | + path_with_hash |
162 | 156 | }
|
163 | 157 |
|
164 | 158 | fn compile(
|
|
0 commit comments