From 08a535a4cbc0b8e0a6e33570d50e8a9e7b7ff35b Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Sat, 3 Nov 2018 20:21:05 +0100 Subject: [PATCH] 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 --- components/malloc_size_of/lib.rs | 30 +++++++++++++++++++ components/script/dom/formdata.rs | 8 ++--- .../metadata/url/urlencoded-parser.any.js.ini | 27 ----------------- 3 files changed, 34 insertions(+), 31 deletions(-) delete mode 100644 tests/wpt/metadata/url/urlencoded-parser.any.js.ini diff --git a/components/malloc_size_of/lib.rs b/components/malloc_size_of/lib.rs index e0f638a843d2..540ff8bffd5d 100644 --- a/components/malloc_size_of/lib.rs +++ b/components/malloc_size_of/lib.rs @@ -557,6 +557,36 @@ where } } +impl MallocShallowSizeOf for std::collections::BTreeMap +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::() + size_of::() + size_of::()) + } + } +} + +impl MallocSizeOf for std::collections::BTreeMap +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 MallocShallowSizeOf for hashglobe::hash_map::HashMap where K: Eq + Hash, diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs index 1ec80600ba4b..7511941abb95 100644 --- a/components/script/dom/formdata.rs +++ b/components/script/dom/formdata.rs @@ -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>>, + data: DomRefCell>>, } impl FormData { fn new_inherited(opt_form: Option<&HTMLFormElement>) -> FormData { - let mut hashmap: HashMap> = HashMap::new(); + let mut hashmap: BTreeMap> = BTreeMap::new(); if let Some(form) = opt_form { for datum in form.get_form_dataset(None) { diff --git a/tests/wpt/metadata/url/urlencoded-parser.any.js.ini b/tests/wpt/metadata/url/urlencoded-parser.any.js.ini deleted file mode 100644 index 8fa49422e95d..000000000000 --- a/tests/wpt/metadata/url/urlencoded-parser.any.js.ini +++ /dev/null @@ -1,27 +0,0 @@ -[urlencoded-parser.any.html] - [request.formData() with input: a&b&c] - expected: FAIL - - [request.formData() with input: a=b&c=d&] - expected: FAIL - - [response.formData() with input: a&b&c] - expected: FAIL - - [response.formData() with input: &&&a=b&&&&c=d&] - expected: FAIL - - -[urlencoded-parser.any.worker.html] - [request.formData() with input: a&b&c] - expected: FAIL - - [response.formData() with input: a&b&c] - expected: FAIL - - [response.formData() with input: a=b&c=d&] - expected: FAIL - - [response.formData() with input: a=b&c=d] - expected: FAIL -