From a94e13f8886211b2ead8d52b3cfe43cd0c8ff998 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 28 Oct 2014 11:24:41 -0700 Subject: [PATCH] script: Use an FNV hash to hash event listeners. The security properties of SipHash are irrelevant for event listeners and the creation of the random number generator was showing up high in the profiles. --- components/script/dom/bindings/trace.rs | 6 ++++-- components/script/dom/eventtarget.rs | 5 +++-- components/script/lib.rs | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 930fd59edbe..c4f59491c57 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -39,7 +39,7 @@ use msg::constellation_msg::{PipelineId, SubpageId, WindowSizeData}; use net::image_cache_task::ImageCacheTask; use script_traits::ScriptControlChan; use std::collections::hashmap::HashMap; -use collections::hash::Hash; +use collections::hash::{Hash, Hasher}; use style::PropertyDeclarationBlock; use std::comm::{Receiver, Sender}; use string_cache::{Atom, Namespace}; @@ -170,7 +170,9 @@ impl JSTraceable for Option { } } -impl JSTraceable for HashMap { +impl JSTraceable for HashMap where K: Eq + Hash + JSTraceable, + V: JSTraceable, + H: Hasher { #[inline] fn trace(&self, trc: *mut JSTracer) { for e in self.iter() { diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index 233047691ea..0ced9c9c41e 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -18,6 +18,7 @@ use dom::xmlhttprequest::XMLHttpRequestId; use dom::virtualmethods::VirtualMethods; use js::jsapi::{JS_CompileUCFunction, JS_GetFunctionObject, JS_CloneFunctionObject}; use js::jsapi::{JSContext, JSObject}; +use servo_util::fnv::FnvHasher; use servo_util::str::DOMString; use libc::{c_char, size_t}; use std::ptr; @@ -69,7 +70,7 @@ pub struct EventListenerEntry { pub struct EventTarget { type_id: EventTargetTypeId, reflector_: Reflector, - handlers: DOMRefCell>>, + handlers: DOMRefCell, FnvHasher>>, } impl EventTarget { @@ -77,7 +78,7 @@ impl EventTarget { EventTarget { type_id: type_id, reflector_: Reflector::new(), - handlers: DOMRefCell::new(HashMap::new()), + handlers: DOMRefCell::new(HashMap::with_hasher(FnvHasher)), } } diff --git a/components/script/lib.rs b/components/script/lib.rs index e03801f5217..02a96942927 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -5,7 +5,7 @@ #![comment = "The Servo Parallel Browser Project"] #![license = "MPL"] -#![feature(globs, macro_rules, struct_variant, phase, unsafe_destructor)] +#![feature(default_type_params, globs, macro_rules, struct_variant, phase, unsafe_destructor)] #![deny(unused_imports, unused_variable)] #![allow(non_snake_case)]