|
1 | 1 | //! Server-side handles and storage for per-handle data.
|
2 | 2 |
|
3 | 3 | use std::collections::{BTreeMap, HashMap};
|
4 |
| -use std::hash::Hash; |
| 4 | +use std::hash::{BuildHasher, Hash}; |
5 | 5 | use std::num::NonZeroU32;
|
6 | 6 | use std::ops::{Index, IndexMut};
|
7 | 7 | use std::sync::atomic::{AtomicUsize, Ordering};
|
@@ -51,15 +51,31 @@ impl<T> IndexMut<Handle> for OwnedStore<T> {
|
51 | 51 | }
|
52 | 52 | }
|
53 | 53 |
|
| 54 | +// HACK(eddyb) deterministic `std::collections::hash_map::RandomState` replacement |
| 55 | +// that doesn't require adding any dependencies to `proc_macro` (like `rustc-hash`). |
| 56 | +#[derive(Clone)] |
| 57 | +struct NonRandomState; |
| 58 | + |
| 59 | +impl BuildHasher for NonRandomState { |
| 60 | + type Hasher = std::collections::hash_map::DefaultHasher; |
| 61 | + #[inline] |
| 62 | + fn build_hasher(&self) -> Self::Hasher { |
| 63 | + Self::Hasher::new() |
| 64 | + } |
| 65 | +} |
| 66 | + |
54 | 67 | /// Like `OwnedStore`, but avoids storing any value more than once.
|
55 | 68 | pub(super) struct InternedStore<T: 'static> {
|
56 | 69 | owned: OwnedStore<T>,
|
57 |
| - interner: HashMap<T, Handle>, |
| 70 | + interner: HashMap<T, Handle, NonRandomState>, |
58 | 71 | }
|
59 | 72 |
|
60 | 73 | impl<T: Copy + Eq + Hash> InternedStore<T> {
|
61 | 74 | pub(super) fn new(counter: &'static AtomicUsize) -> Self {
|
62 |
| - InternedStore { owned: OwnedStore::new(counter), interner: HashMap::new() } |
| 75 | + InternedStore { |
| 76 | + owned: OwnedStore::new(counter), |
| 77 | + interner: HashMap::with_hasher(NonRandomState), |
| 78 | + } |
63 | 79 | }
|
64 | 80 |
|
65 | 81 | pub(super) fn alloc(&mut self, x: T) -> Handle {
|
|
0 commit comments