Pass around event types as Atoms instead of Strings

`Event` internally stores the `type` as an `Atom`, and we're `String`s
everywhere, which can cause unnecessary allocations to occur since
they'll end up as `Atom`s anyways.
This commit is contained in:
Corey Farwell 2015-12-10 22:06:05 -05:00
parent 996c0a60b8
commit 4accaf50b2
25 changed files with 156 additions and 135 deletions

View file

@ -12,6 +12,7 @@ use dom::bindings::js::Root;
use dom::bindings::reflector::reflect_dom_object;
use dom::event::{Event, EventBubbles, EventCancelable};
use script_task::ScriptChan;
use string_cache::Atom;
use util::str::DOMString;
#[dom_struct]
@ -33,7 +34,7 @@ impl CloseEvent {
}
pub fn new(global: GlobalRef,
type_: DOMString,
type_: Atom,
bubbles: EventBubbles,
cancelable: EventCancelable,
wasClean: bool,
@ -44,9 +45,9 @@ impl CloseEvent {
let ev = reflect_dom_object(event, global, CloseEventBinding::Wrap);
{
let event = ev.upcast::<Event>();
event.InitEvent(type_,
bubbles == EventBubbles::Bubbles,
cancelable == EventCancelable::Cancelable);
event.init_event(type_,
bubbles == EventBubbles::Bubbles,
cancelable == EventCancelable::Cancelable);
}
ev
}
@ -66,7 +67,7 @@ impl CloseEvent {
EventCancelable::NotCancelable
};
Ok(CloseEvent::new(global,
type_,
Atom::from(&*type_),
bubbles,
cancelable,
init.wasClean,