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::inheritance::Castable;
use dom::bindings::js::Root;
use dom::bindings::reflector::reflect_dom_object;
use dom::event::{Event, EventBubbles, EventCancelable};
use string_cache::Atom;
use util::str::DOMString;
#[dom_struct]
@ -36,7 +37,7 @@ impl WebGLContextEvent {
}
pub fn new(global: GlobalRef,
type_: DOMString,
type_: Atom,
bubbles: EventBubbles,
cancelable: EventCancelable,
status_message: DOMString) -> Root<WebGLContextEvent> {
@ -47,7 +48,7 @@ impl WebGLContextEvent {
{
let parent = event.upcast::<Event>();
parent.InitEvent(type_, bubbles == EventBubbles::Bubbles, cancelable == EventCancelable::Cancelable);
parent.init_event(type_, bubbles == EventBubbles::Bubbles, cancelable == EventCancelable::Cancelable);
}
event
@ -73,7 +74,7 @@ impl WebGLContextEvent {
EventCancelable::NotCancelable
};
Ok(WebGLContextEvent::new(global, type_,
Ok(WebGLContextEvent::new(global, Atom::from(&*type_),
bubbles,
cancelable,
status_message))