Skip to content

Commit

Permalink
Use a BTreeMap to store formdata
Browse files Browse the repository at this point in the history
I'm really unsure about the MallocSizeOf of BTreeMap as I took the same
code as for HashMap.

Fixes #13105
Fixes #21381
  • Loading branch information
Eijebong committed Nov 5, 2018
1 parent 176d984 commit 08a535a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
30 changes: 30 additions & 0 deletions components/malloc_size_of/lib.rs
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions components/script/dom/formdata.rs
Expand Up @@ -18,19 +18,19 @@ use dom::globalscope::GlobalScope;
use dom::htmlformelement::{HTMLFormElement, FormDatumValue, FormDatum};
use dom_struct::dom_struct;
use html5ever::LocalName;
use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::collections::BTreeMap;
use std::collections::btree_map::Entry::{Occupied, Vacant};
use std::iter;

#[dom_struct]
pub struct FormData {
reflector_: Reflector,
data: DomRefCell<HashMap<LocalName, Vec<FormDatum>>>,
data: DomRefCell<BTreeMap<LocalName, Vec<FormDatum>>>,
}

impl FormData {
fn new_inherited(opt_form: Option<&HTMLFormElement>) -> FormData {
let mut hashmap: HashMap<LocalName, Vec<FormDatum>> = HashMap::new();
let mut hashmap: BTreeMap<LocalName, Vec<FormDatum>> = BTreeMap::new();

if let Some(form) = opt_form {
for datum in form.get_form_dataset(None) {
Expand Down
27 changes: 0 additions & 27 deletions tests/wpt/metadata/url/urlencoded-parser.any.js.ini

This file was deleted.

0 comments on commit 08a535a

Please sign in to comment.