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.
This commit is contained in:
Patrick Walton 2014-10-28 11:24:41 -07:00
parent 8ab354ac08
commit a94e13f888
3 changed files with 8 additions and 5 deletions

View file

@ -39,7 +39,7 @@ use msg::constellation_msg::{PipelineId, SubpageId, WindowSizeData};
use net::image_cache_task::ImageCacheTask; use net::image_cache_task::ImageCacheTask;
use script_traits::ScriptControlChan; use script_traits::ScriptControlChan;
use std::collections::hashmap::HashMap; use std::collections::hashmap::HashMap;
use collections::hash::Hash; use collections::hash::{Hash, Hasher};
use style::PropertyDeclarationBlock; use style::PropertyDeclarationBlock;
use std::comm::{Receiver, Sender}; use std::comm::{Receiver, Sender};
use string_cache::{Atom, Namespace}; use string_cache::{Atom, Namespace};
@ -170,7 +170,9 @@ impl<T: JSTraceable> JSTraceable for Option<T> {
} }
} }
impl<K: Eq+Hash+JSTraceable, V: JSTraceable> JSTraceable for HashMap<K, V> { impl<K,V,S,H> JSTraceable for HashMap<K, V, H> where K: Eq + Hash<S> + JSTraceable,
V: JSTraceable,
H: Hasher<S> {
#[inline] #[inline]
fn trace(&self, trc: *mut JSTracer) { fn trace(&self, trc: *mut JSTracer) {
for e in self.iter() { for e in self.iter() {

View file

@ -18,6 +18,7 @@ use dom::xmlhttprequest::XMLHttpRequestId;
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use js::jsapi::{JS_CompileUCFunction, JS_GetFunctionObject, JS_CloneFunctionObject}; use js::jsapi::{JS_CompileUCFunction, JS_GetFunctionObject, JS_CloneFunctionObject};
use js::jsapi::{JSContext, JSObject}; use js::jsapi::{JSContext, JSObject};
use servo_util::fnv::FnvHasher;
use servo_util::str::DOMString; use servo_util::str::DOMString;
use libc::{c_char, size_t}; use libc::{c_char, size_t};
use std::ptr; use std::ptr;
@ -69,7 +70,7 @@ pub struct EventListenerEntry {
pub struct EventTarget { pub struct EventTarget {
type_id: EventTargetTypeId, type_id: EventTargetTypeId,
reflector_: Reflector, reflector_: Reflector,
handlers: DOMRefCell<HashMap<DOMString, Vec<EventListenerEntry>>>, handlers: DOMRefCell<HashMap<DOMString, Vec<EventListenerEntry>, FnvHasher>>,
} }
impl EventTarget { impl EventTarget {
@ -77,7 +78,7 @@ impl EventTarget {
EventTarget { EventTarget {
type_id: type_id, type_id: type_id,
reflector_: Reflector::new(), reflector_: Reflector::new(),
handlers: DOMRefCell::new(HashMap::new()), handlers: DOMRefCell::new(HashMap::with_hasher(FnvHasher)),
} }
} }

View file

@ -5,7 +5,7 @@
#![comment = "The Servo Parallel Browser Project"] #![comment = "The Servo Parallel Browser Project"]
#![license = "MPL"] #![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)] #![deny(unused_imports, unused_variable)]
#![allow(non_snake_case)] #![allow(non_snake_case)]