diff options
author | Nicholas Nethercote <nnethercote@mozilla.com> | 2017-10-18 10:42:01 +1100 |
---|---|---|
committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2017-10-18 22:20:37 +1100 |
commit | 4506f0d30cbbb02df32e9c16135ef288ad6b7e2e (patch) | |
tree | 9a3de6bfdfabc6dee92352fb18df31e2468acf07 /components/script/dom/eventtarget.rs | |
parent | 421baa854ea40c7b1a3d1e75acac14da04a3fbcc (diff) | |
download | servo-4506f0d30cbbb02df32e9c16135ef288ad6b7e2e.tar.gz servo-4506f0d30cbbb02df32e9c16135ef288ad6b7e2e.zip |
Replace all uses of the `heapsize` crate with `malloc_size_of`.
Servo currently uses `heapsize`, but Stylo/Gecko use `malloc_size_of`.
`malloc_size_of` is better -- it handles various cases that `heapsize` does not
-- so this patch changes Servo to use `malloc_size_of`.
This patch makes the following changes to the `malloc_size_of` crate.
- Adds `MallocSizeOf` trait implementations for numerous types, some built-in
(e.g. `VecDeque`), some external and Servo-only (e.g. `string_cache`).
- Makes `enclosing_size_of_op` optional, because vanilla jemalloc doesn't
support that operation.
- For `HashSet`/`HashMap`, falls back to a computed estimate when
`enclosing_size_of_op` isn't available.
- Adds an extern "C" `malloc_size_of` function that does the actual heap
measurement; this is based on the same functions from the `heapsize` crate.
This patch makes the following changes elsewhere.
- Converts all the uses of `heapsize` to instead use `malloc_size_of`.
- Disables the "heapsize"/"heap_size" feature for the external crates that
provide it.
- Removes the `HeapSizeOf` implementation from `hashglobe`.
- Adds `ignore` annotations to a few `Rc`/`Arc`, because `malloc_size_of`
doesn't derive those types, unlike `heapsize`.
Diffstat (limited to 'components/script/dom/eventtarget.rs')
-rw-r--r-- | components/script/dom/eventtarget.rs | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index e5b8c86e71e..558610fc99f 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -32,7 +32,6 @@ use dom::virtualmethods::VirtualMethods; use dom::window::Window; use dom_struct::dom_struct; use fnv::FnvHasher; -use heapsize::HeapSizeOf; use js::jsapi::{CompileFunction, JS_GetFunctionObject, JSAutoCompartment}; use js::rust::{AutoObjectVectorWrapper, CompileOptionsWrapper}; use libc::{c_char, size_t}; @@ -48,11 +47,19 @@ use std::ops::{Deref, DerefMut}; use std::ptr; use std::rc::Rc; -#[derive(Clone, JSTraceable, PartialEq)] +#[derive(Clone, JSTraceable, MallocSizeOf, PartialEq)] pub enum CommonEventHandler { - EventHandler(Rc<EventHandlerNonNull>), - ErrorEventHandler(Rc<OnErrorEventHandlerNonNull>), - BeforeUnloadEventHandler(Rc<OnBeforeUnloadEventHandlerNonNull>), + EventHandler( + #[ignore_malloc_size_of = "Rc"] + Rc<EventHandlerNonNull>), + + ErrorEventHandler( + #[ignore_malloc_size_of = "Rc"] + Rc<OnErrorEventHandlerNonNull>), + + BeforeUnloadEventHandler( + #[ignore_malloc_size_of = "Rc"] + Rc<OnBeforeUnloadEventHandlerNonNull>), } impl CommonEventHandler { @@ -65,14 +72,14 @@ impl CommonEventHandler { } } -#[derive(Clone, Copy, HeapSizeOf, JSTraceable, PartialEq)] +#[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)] pub enum ListenerPhase { Capturing, Bubbling, } /// <https://html.spec.whatwg.org/multipage/#internal-raw-uncompiled-handler> -#[derive(Clone, JSTraceable, PartialEq)] +#[derive(Clone, JSTraceable, MallocSizeOf, PartialEq)] struct InternalRawUncompiledHandler { source: DOMString, url: ServoUrl, @@ -80,7 +87,7 @@ struct InternalRawUncompiledHandler { } /// A representation of an event handler, either compiled or uncompiled raw source, or null. -#[derive(Clone, JSTraceable, PartialEq)] +#[derive(Clone, JSTraceable, MallocSizeOf, PartialEq)] enum InlineEventListener { Uncompiled(InternalRawUncompiledHandler), Compiled(CommonEventHandler), @@ -110,19 +117,12 @@ impl InlineEventListener { } } -#[derive(Clone, JSTraceable, PartialEq)] +#[derive(Clone, JSTraceable, MallocSizeOf, PartialEq)] enum EventListenerType { - Additive(Rc<EventListener>), + Additive(#[ignore_malloc_size_of = "Rc"] Rc<EventListener>), Inline(InlineEventListener), } -impl HeapSizeOf for EventListenerType { - fn heap_size_of_children(&self) -> usize { - // FIXME: Rc<T> isn't HeapSizeOf and we can't ignore it due to #6870 and #6871 - 0 - } -} - impl EventListenerType { fn get_compiled_listener(&mut self, owner: &EventTarget, ty: &Atom) -> Option<CompiledEventListener> { @@ -225,14 +225,14 @@ impl CompiledEventListener { } } -#[derive(Clone, DenyPublicFields, HeapSizeOf, JSTraceable, PartialEq)] +#[derive(Clone, DenyPublicFields, JSTraceable, MallocSizeOf, PartialEq)] /// A listener in a collection of event listeners. struct EventListenerEntry { phase: ListenerPhase, listener: EventListenerType } -#[derive(HeapSizeOf, JSTraceable)] +#[derive(JSTraceable, MallocSizeOf)] /// A mix of potentially uncompiled and compiled event listeners of the same type. struct EventListeners(Vec<EventListenerEntry>); |