mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
script: Make PartialEq
on element type IDs generate a lot less code.
This makes the difference between selector matching scaling on the ARM Cortex-A9 and not, because the auto-derived `PartialEq` implementation blows out the 32KB I-cache. With this change, there is a 2x improvement in selector matching over sequential when using all 8 cores. (More work needs to be done; this is a start.)
This commit is contained in:
parent
41095c01a7
commit
8c210e1a27
4 changed files with 83 additions and 8 deletions
|
@ -28,6 +28,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
|
|||
use std::collections::hash_state::DefaultState;
|
||||
use std::default::Default;
|
||||
use std::ffi::CString;
|
||||
use std::intrinsics;
|
||||
use std::ptr;
|
||||
use url::Url;
|
||||
|
||||
|
@ -40,7 +41,7 @@ pub enum ListenerPhase {
|
|||
Bubbling,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
#[derive(Copy, Clone)]
|
||||
#[jstraceable]
|
||||
pub enum EventTargetTypeId {
|
||||
Node(NodeTypeId),
|
||||
|
@ -51,6 +52,42 @@ pub enum EventTargetTypeId {
|
|||
XMLHttpRequestEventTarget(XMLHttpRequestEventTargetTypeId)
|
||||
}
|
||||
|
||||
impl PartialEq for EventTargetTypeId {
|
||||
#[inline]
|
||||
fn eq(&self, other: &EventTargetTypeId) -> bool {
|
||||
match (*self, *other) {
|
||||
(EventTargetTypeId::Node(this_type), EventTargetTypeId::Node(other_type)) => {
|
||||
this_type == other_type
|
||||
}
|
||||
_ => self.eq_slow(other)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EventTargetTypeId {
|
||||
#[allow(unsafe_code)]
|
||||
fn eq_slow(&self, other: &EventTargetTypeId) -> bool {
|
||||
match (*self, *other) {
|
||||
(EventTargetTypeId::Node(this_type), EventTargetTypeId::Node(other_type)) => {
|
||||
this_type == other_type
|
||||
}
|
||||
(EventTargetTypeId::WorkerGlobalScope(this_type),
|
||||
EventTargetTypeId::WorkerGlobalScope(other_type)) => {
|
||||
this_type == other_type
|
||||
}
|
||||
(EventTargetTypeId::XMLHttpRequestEventTarget(this_type),
|
||||
EventTargetTypeId::XMLHttpRequestEventTarget(other_type)) => {
|
||||
this_type == other_type
|
||||
}
|
||||
(_, _) => {
|
||||
unsafe {
|
||||
intrinsics::discriminant_value(self) == intrinsics::discriminant_value(other)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
#[jstraceable]
|
||||
pub enum EventListenerType {
|
||||
|
|
|
@ -36,6 +36,7 @@ use string_cache::Atom;
|
|||
|
||||
use std::borrow::ToOwned;
|
||||
use std::default::Default;
|
||||
use std::intrinsics;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct HTMLElement {
|
||||
|
@ -303,7 +304,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLElement> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[jstraceable]
|
||||
pub enum HTMLElementTypeId {
|
||||
HTMLElement,
|
||||
|
@ -374,3 +375,25 @@ pub enum HTMLElementTypeId {
|
|||
HTMLUnknownElement,
|
||||
}
|
||||
|
||||
impl PartialEq for HTMLElementTypeId {
|
||||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
fn eq(&self, other: &HTMLElementTypeId) -> bool {
|
||||
match (*self, *other) {
|
||||
(HTMLElementTypeId::HTMLMediaElement(this_type),
|
||||
HTMLElementTypeId::HTMLMediaElement(other_type)) => {
|
||||
this_type == other_type
|
||||
}
|
||||
(HTMLElementTypeId::HTMLTableCellElement(this_type),
|
||||
HTMLElementTypeId::HTMLTableCellElement(other_type)) => {
|
||||
this_type == other_type
|
||||
}
|
||||
(_, _) => {
|
||||
unsafe {
|
||||
intrinsics::discriminant_value(self) == intrinsics::discriminant_value(other)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,10 +42,17 @@ impl HTMLMediaElement {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[jstraceable]
|
||||
pub enum HTMLMediaElementTypeId {
|
||||
HTMLAudioElement,
|
||||
HTMLVideoElement,
|
||||
HTMLAudioElement = 0,
|
||||
HTMLVideoElement = 1,
|
||||
}
|
||||
|
||||
impl PartialEq for HTMLMediaElementTypeId {
|
||||
#[inline]
|
||||
fn eq(&self, other: &HTMLMediaElementTypeId) -> bool {
|
||||
(*self as u8) == (*other as u8)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,11 +23,18 @@ use std::cmp::max;
|
|||
|
||||
const DEFAULT_COLSPAN: u32 = 1;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[jstraceable]
|
||||
pub enum HTMLTableCellElementTypeId {
|
||||
HTMLTableDataCellElement,
|
||||
HTMLTableHeaderCellElement,
|
||||
HTMLTableDataCellElement = 0,
|
||||
HTMLTableHeaderCellElement = 1,
|
||||
}
|
||||
|
||||
impl PartialEq for HTMLTableCellElementTypeId {
|
||||
#[inline]
|
||||
fn eq(&self, other: &HTMLTableCellElementTypeId) -> bool {
|
||||
(*self as u8) == (*other as u8)
|
||||
}
|
||||
}
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -143,3 +150,4 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableCellElement> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue