mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
auto merge of #3623 : pcwalton/servo/use-atoms-2, r=jdm
75% improvement in style recalc for Guardians of the Galaxy.
This commit is contained in:
commit
8077edc062
31 changed files with 305 additions and 237 deletions
|
@ -226,7 +226,7 @@ impl<'a> FlowConstructor<'a> {
|
|||
//FIXME: would it make more sense to use HTMLInputElement::input_type instead of the raw
|
||||
// value? definitely for string comparisons.
|
||||
let elem = node.as_element();
|
||||
let data = match elem.get_attr(&ns!(""), "type") {
|
||||
let data = match elem.get_attr(&ns!(""), &atom!("type")) {
|
||||
Some("checkbox") | Some("radio") => None,
|
||||
Some("button") | Some("submit") | Some("reset") =>
|
||||
Some(node.get_input_value().len() as u32),
|
||||
|
@ -1158,7 +1158,7 @@ trait ObjectElement<'a> {
|
|||
impl<'ln> ObjectElement<'ln> for ThreadSafeLayoutNode<'ln> {
|
||||
fn get_type_and_data(&self) -> (Option<&'ln str>, Option<&'ln str>) {
|
||||
let elem = self.as_element();
|
||||
(elem.get_attr(&ns!(""), "type"), elem.get_attr(&ns!(""), "data"))
|
||||
(elem.get_attr(&ns!(""), &atom!("type")), elem.get_attr(&ns!(""), &atom!("data")))
|
||||
}
|
||||
|
||||
fn has_object_data(&self) -> bool {
|
||||
|
|
|
@ -15,7 +15,6 @@ use script::dom::node::{TextNodeTypeId};
|
|||
use servo_util::bloom::BloomFilter;
|
||||
use servo_util::cache::{Cache, LRUCache, SimpleHashCache};
|
||||
use servo_util::smallvec::{SmallVec, SmallVec16};
|
||||
use servo_util::str::DOMString;
|
||||
use std::mem;
|
||||
use std::hash::{Hash, sip};
|
||||
use std::slice::Items;
|
||||
|
@ -165,7 +164,8 @@ pub struct StyleSharingCandidate {
|
|||
pub style: Arc<ComputedValues>,
|
||||
pub parent_style: Arc<ComputedValues>,
|
||||
pub local_name: Atom,
|
||||
pub class: Option<DOMString>,
|
||||
// FIXME(pcwalton): Should be a list of atoms instead.
|
||||
pub class: Option<String>,
|
||||
}
|
||||
|
||||
impl PartialEq for StyleSharingCandidate {
|
||||
|
@ -222,7 +222,7 @@ impl StyleSharingCandidate {
|
|||
style: style,
|
||||
parent_style: parent_style,
|
||||
local_name: element.get_local_name().clone(),
|
||||
class: element.get_attr(&ns!(""), "class")
|
||||
class: element.get_attr(&ns!(""), &atom!("class"))
|
||||
.map(|string| string.to_string()),
|
||||
})
|
||||
}
|
||||
|
@ -231,10 +231,12 @@ impl StyleSharingCandidate {
|
|||
if *element.get_local_name() != self.local_name {
|
||||
return false
|
||||
}
|
||||
match (&self.class, element.get_attr(&ns!(""), "class")) {
|
||||
|
||||
// FIXME(pcwalton): Use `each_class` here instead of slow string comparison.
|
||||
match (&self.class, element.get_attr(&ns!(""), &atom!("class"))) {
|
||||
(&None, Some(_)) | (&Some(_), None) => return false,
|
||||
(&Some(ref this_class), Some(element_class))
|
||||
if element_class != this_class.as_slice() => {
|
||||
(&Some(ref this_class), Some(element_class)) if
|
||||
element_class != this_class.as_slice() => {
|
||||
return false
|
||||
}
|
||||
(&Some(_), Some(_)) | (&None, None) => {}
|
||||
|
@ -457,7 +459,8 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
|
|||
}
|
||||
let ok = {
|
||||
let element = self.as_element();
|
||||
element.style_attribute().is_none() && element.get_attr(&ns!(""), "id").is_none()
|
||||
element.style_attribute().is_none() &&
|
||||
element.get_attr(&ns!(""), &atom!("id")).is_none()
|
||||
};
|
||||
if !ok {
|
||||
return CannotShare(false)
|
||||
|
|
|
@ -48,6 +48,7 @@ use std::cmp::{max, min};
|
|||
use std::fmt;
|
||||
use std::from_str::FromStr;
|
||||
use std::num::Zero;
|
||||
use string_cache::Atom;
|
||||
use style::{ComputedValues, TElement, TNode, cascade_anonymous, RGBA};
|
||||
use style::computed_values::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
use style::computed_values::{LengthOrPercentageOrNone};
|
||||
|
@ -220,7 +221,7 @@ impl ImageFragmentInfo {
|
|||
image_url: Url,
|
||||
local_image_cache: Arc<Mutex<LocalImageCache<UntrustedNodeAddress>>>)
|
||||
-> ImageFragmentInfo {
|
||||
fn convert_length(node: &ThreadSafeLayoutNode, name: &str) -> Option<Au> {
|
||||
fn convert_length(node: &ThreadSafeLayoutNode, name: &Atom) -> Option<Au> {
|
||||
let element = node.as_element();
|
||||
element.get_attr(&ns!(""), name).and_then(|string| {
|
||||
let n: Option<int> = FromStr::from_str(string);
|
||||
|
@ -229,8 +230,8 @@ impl ImageFragmentInfo {
|
|||
}
|
||||
|
||||
let is_vertical = node.style().writing_mode.is_vertical();
|
||||
let dom_width = convert_length(node, "width");
|
||||
let dom_height = convert_length(node, "height");
|
||||
let dom_width = convert_length(node, &atom!("width"));
|
||||
let dom_height = convert_length(node, &atom!("height"));
|
||||
|
||||
let opaque_node: OpaqueNode = OpaqueNodeMethods::from_thread_safe_layout_node(node);
|
||||
let untrusted_node: UntrustedNodeAddress = opaque_node.to_untrusted_node_address();
|
||||
|
@ -412,7 +413,7 @@ impl TableColumnFragmentInfo {
|
|||
pub fn new(node: &ThreadSafeLayoutNode) -> TableColumnFragmentInfo {
|
||||
let span = {
|
||||
let element = node.as_element();
|
||||
element.get_attr(&ns!(""), "span").and_then(|string| {
|
||||
element.get_attr(&ns!(""), &atom!("span")).and_then(|string| {
|
||||
let n: Option<int> = FromStr::from_str(string);
|
||||
n
|
||||
})
|
||||
|
|
|
@ -28,9 +28,10 @@ extern crate "net" as servo_net;
|
|||
extern crate "msg" as servo_msg;
|
||||
#[phase(plugin, link)]
|
||||
extern crate "util" as servo_util;
|
||||
extern crate string_cache;
|
||||
|
||||
#[phase(plugin)]
|
||||
extern crate string_cache_macros;
|
||||
extern crate string_cache;
|
||||
|
||||
extern crate collections;
|
||||
extern crate encoding;
|
||||
|
|
|
@ -317,15 +317,14 @@ impl<'ln> TNode<'ln, LayoutElement<'ln>> for LayoutNode<'ln> {
|
|||
fn match_attr(self, attr: &AttrSelector, test: |&str| -> bool) -> bool {
|
||||
assert!(self.is_element())
|
||||
let name = if self.is_html_element_in_html_document() {
|
||||
attr.lower_name.as_slice()
|
||||
&attr.lower_name
|
||||
} else {
|
||||
attr.name.as_slice()
|
||||
&attr.name
|
||||
};
|
||||
match attr.namespace {
|
||||
SpecificNamespace(ref ns) => {
|
||||
let element = self.as_element();
|
||||
element.get_attr(ns, name)
|
||||
.map_or(false, |attr| test(attr))
|
||||
element.get_attr(ns, name).map_or(false, |attr| test(attr))
|
||||
},
|
||||
AnyNamespace => {
|
||||
let element = self.as_element();
|
||||
|
@ -445,13 +444,15 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn get_attr(self, namespace: &Namespace, name: &str) -> Option<&'le str> {
|
||||
fn get_attr(self, namespace: &Namespace, name: &Atom) -> Option<&'le str> {
|
||||
unsafe { self.element.get_attr_val_for_layout(namespace, name) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_attrs(self, name: &str) -> Vec<&'le str> {
|
||||
unsafe { self.element.get_attr_vals_for_layout(name) }
|
||||
fn get_attrs(self, name: &Atom) -> Vec<&'le str> {
|
||||
unsafe {
|
||||
self.element.get_attr_vals_for_layout(name)
|
||||
}
|
||||
}
|
||||
|
||||
fn get_link(self) -> Option<&'le str> {
|
||||
|
@ -462,7 +463,9 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
|
|||
ElementNodeTypeId(HTMLAnchorElementTypeId) |
|
||||
ElementNodeTypeId(HTMLAreaElementTypeId) |
|
||||
ElementNodeTypeId(HTMLLinkElementTypeId) => {
|
||||
unsafe { self.element.get_attr_val_for_layout(&ns!(""), "href") }
|
||||
unsafe {
|
||||
self.element.get_attr_val_for_layout(&ns!(""), &atom!("href"))
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
|
@ -476,7 +479,9 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
|
|||
|
||||
#[inline]
|
||||
fn get_id(self) -> Option<Atom> {
|
||||
unsafe { self.element.get_attr_atom_for_layout(&ns!(""), "id") }
|
||||
unsafe {
|
||||
self.element.get_attr_atom_for_layout(&ns!(""), &atom!("id"))
|
||||
}
|
||||
}
|
||||
|
||||
fn get_disabled_state(self) -> bool {
|
||||
|
@ -491,7 +496,7 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
|
|||
}
|
||||
}
|
||||
|
||||
fn has_class(self, name: &str) -> bool {
|
||||
fn has_class(self, name: &Atom) -> bool {
|
||||
unsafe {
|
||||
self.element.has_class_for_layout(name)
|
||||
}
|
||||
|
@ -502,8 +507,8 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
|
|||
unsafe {
|
||||
match self.element.get_classes_for_layout() {
|
||||
None => {}
|
||||
Some(mut classes) => {
|
||||
for class in classes {
|
||||
Some(ref classes) => {
|
||||
for class in classes.iter() {
|
||||
callback(class)
|
||||
}
|
||||
}
|
||||
|
@ -867,8 +872,10 @@ pub struct ThreadSafeLayoutElement<'le> {
|
|||
|
||||
impl<'le> ThreadSafeLayoutElement<'le> {
|
||||
#[inline]
|
||||
pub fn get_attr(&self, namespace: &Namespace, name: &str) -> Option<&'le str> {
|
||||
unsafe { self.element.get_attr_val_for_layout(namespace, name) }
|
||||
pub fn get_attr(&self, namespace: &Namespace, name: &Atom) -> Option<&'le str> {
|
||||
unsafe {
|
||||
self.element.get_attr_val_for_layout(namespace, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue