hashglobe: Add a shim on top of OrderMap.

This commit is contained in:
Emilio Cobos Álvarez 2018-01-31 15:13:02 +01:00
parent c88dc51d03
commit a2c2d34753
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
6 changed files with 357 additions and 0 deletions

View file

@ -49,6 +49,7 @@ extern crate euclid;
extern crate hashglobe;
#[cfg(feature = "servo")]
extern crate mozjs as js;
extern crate ordermap;
extern crate selectors;
extern crate servo_arc;
extern crate smallbitvec;
@ -409,6 +410,33 @@ impl<T, S> MallocShallowSizeOf for hashglobe::hash_set::HashSet<T, S>
}
}
impl<T, S> MallocSizeOf for ordermap::OrderSet<T, S>
where T: Eq + Hash + MallocSizeOf,
S: BuildHasher,
{
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
let mut n = self.shallow_size_of(ops);
for t in self.iter() {
n += t.size_of(ops);
}
n
}
}
impl<T, S> MallocShallowSizeOf for ordermap::OrderSet<T, S>
where T: Eq + Hash,
S: BuildHasher
{
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
// See the implementation for std::collections::HashSet for details.
if ops.has_malloc_enclosing_size_of() {
self.iter().next().map_or(0, |t| unsafe { ops.malloc_enclosing_size_of(t) })
} else {
self.capacity() * (size_of::<T>() + size_of::<usize>())
}
}
}
impl<T, S> MallocSizeOf for hashglobe::hash_set::HashSet<T, S>
where T: Eq + Hash + MallocSizeOf,
S: BuildHasher,
@ -442,6 +470,26 @@ impl<T, S> MallocSizeOf for hashglobe::fake::HashSet<T, S>
}
}
impl<T, S> MallocShallowSizeOf for hashglobe::order::HashSet<T, S>
where T: Eq + Hash,
S: BuildHasher,
{
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
use std::ops::Deref;
self.deref().shallow_size_of(ops)
}
}
impl<T, S> MallocSizeOf for hashglobe::order::HashSet<T, S>
where T: Eq + Hash + MallocSizeOf,
S: BuildHasher,
{
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
use std::ops::Deref;
self.deref().size_of(ops)
}
}
impl<K, V, S> MallocShallowSizeOf for std::collections::HashMap<K, V, S>
where K: Eq + Hash,
S: BuildHasher
@ -471,6 +519,35 @@ impl<K, V, S> MallocSizeOf for std::collections::HashMap<K, V, S>
}
}
impl<K, V, S> MallocShallowSizeOf for ordermap::OrderMap<K, V, S>
where K: Eq + Hash,
S: BuildHasher
{
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
// See the implementation for std::collections::HashSet for details.
if ops.has_malloc_enclosing_size_of() {
self.values().next().map_or(0, |v| unsafe { ops.malloc_enclosing_size_of(v) })
} else {
self.capacity() * (size_of::<V>() + size_of::<K>() + size_of::<usize>())
}
}
}
impl<K, V, S> MallocSizeOf for ordermap::OrderMap<K, V, S>
where K: Eq + Hash + MallocSizeOf,
V: MallocSizeOf,
S: BuildHasher,
{
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
let mut n = self.shallow_size_of(ops);
for (k, v) in self.iter() {
n += k.size_of(ops);
n += v.size_of(ops);
}
n
}
}
impl<K, V, S> MallocShallowSizeOf for hashglobe::hash_map::HashMap<K, V, S>
where K: Eq + Hash,
S: BuildHasher
@ -521,6 +598,27 @@ impl<K, V, S> MallocSizeOf for hashglobe::fake::HashMap<K, V, S>
}
}
impl<K, V, S> MallocShallowSizeOf for hashglobe::order::HashMap<K, V, S>
where K: Eq + Hash,
S: BuildHasher,
{
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
use std::ops::Deref;
self.deref().shallow_size_of(ops)
}
}
impl<K, V, S> MallocSizeOf for hashglobe::order::HashMap<K, V, S>
where K: Eq + Hash + MallocSizeOf,
V: MallocSizeOf,
S: BuildHasher,
{
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
use std::ops::Deref;
self.deref().size_of(ops)
}
}
// PhantomData is always 0.
impl<T> MallocSizeOf for std::marker::PhantomData<T> {
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {