зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #13676 - Remove usage of deprecated `SipHasher` (from servo:no-siphasher); r=pcwalton
<!-- Please describe your changes on the following line: --> <s>Hashing in `SimpleHashCache` is not randomized anymore. Does this matter?</s> r? @pcwalton --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: ef7423bf0034a41b12ba50e623c9b3dba39a53bc
This commit is contained in:
Родитель
daf848c2d7
Коммит
815f962e81
|
@ -4,9 +4,8 @@
|
||||||
|
|
||||||
//! Two simple cache data structures.
|
//! Two simple cache data structures.
|
||||||
|
|
||||||
use rand;
|
use std::collections::hash_map::RandomState;
|
||||||
use rand::Rng;
|
use std::hash::{Hash, Hasher, BuildHasher};
|
||||||
use std::hash::{Hash, Hasher, SipHasher};
|
|
||||||
use std::slice::{Iter, IterMut};
|
use std::slice::{Iter, IterMut};
|
||||||
|
|
||||||
pub struct LRUCache<K, V> {
|
pub struct LRUCache<K, V> {
|
||||||
|
@ -72,17 +71,14 @@ impl<K: PartialEq, V: Clone> LRUCache<K, V> {
|
||||||
|
|
||||||
pub struct SimpleHashCache<K, V> {
|
pub struct SimpleHashCache<K, V> {
|
||||||
entries: Vec<Option<(K, V)>>,
|
entries: Vec<Option<(K, V)>>,
|
||||||
k0: u64,
|
random: RandomState,
|
||||||
k1: u64,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Clone + Eq + Hash, V: Clone> SimpleHashCache<K, V> {
|
impl<K: Clone + Eq + Hash, V: Clone> SimpleHashCache<K, V> {
|
||||||
pub fn new(cache_size: usize) -> SimpleHashCache<K, V> {
|
pub fn new(cache_size: usize) -> SimpleHashCache<K, V> {
|
||||||
let mut r = rand::thread_rng();
|
|
||||||
SimpleHashCache {
|
SimpleHashCache {
|
||||||
entries: vec![None; cache_size],
|
entries: vec![None; cache_size],
|
||||||
k0: r.gen(),
|
random: RandomState::new(),
|
||||||
k1: r.gen(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +89,7 @@ impl<K: Clone + Eq + Hash, V: Clone> SimpleHashCache<K, V> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn bucket_for_key<Q: Hash>(&self, key: &Q) -> usize {
|
fn bucket_for_key<Q: Hash>(&self, key: &Q) -> usize {
|
||||||
let mut hasher = SipHasher::new_with_keys(self.k0, self.k1);
|
let mut hasher = self.random.build_hasher();
|
||||||
key.hash(&mut hasher);
|
key.hash(&mut hasher);
|
||||||
self.to_bucket(hasher.finish() as usize)
|
self.to_bucket(hasher.finish() as usize)
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче