mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #22103 - Eijebong:formdata, r=jdm
Use a BTreeMap to store formdata I'm really unsure about the MallocSizeOf of BTreeMap as I took the same code as for HashMap. Fixes #13105 Fixes #21381 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22103) <!-- Reviewable:end -->
This commit is contained in:
commit
c86b183d5d
3 changed files with 34 additions and 31 deletions
|
@ -557,6 +557,36 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<K, V> MallocShallowSizeOf for std::collections::BTreeMap<K, V>
|
||||
where
|
||||
K: Eq + Hash,
|
||||
{
|
||||
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||
if ops.has_malloc_enclosing_size_of() {
|
||||
self.values()
|
||||
.next()
|
||||
.map_or(0, |v| unsafe { ops.malloc_enclosing_size_of(v) })
|
||||
} else {
|
||||
self.len() * (size_of::<V>() + size_of::<K>() + size_of::<usize>())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> MallocSizeOf for std::collections::BTreeMap<K, V>
|
||||
where
|
||||
K: Eq + Hash + MallocSizeOf,
|
||||
V: MallocSizeOf,
|
||||
{
|
||||
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue