aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-07-05 18:55:36 -0700
committerGitHub <noreply@github.com>2016-07-05 18:55:36 -0700
commitabdf2f28a0bd25a76a31b4fd2410c7a87448ed54 (patch)
tree762287ff3121993d51e3741e84a2a99ac93435ce /components/script/dom
parent3d557b6f25eb9dbd084cb53bbc9a9cf93bad825b (diff)
parent187a47d89d2a4187abca85690429f85293e618cd (diff)
downloadservo-abdf2f28a0bd25a76a31b4fd2410c7a87448ed54.tar.gz
servo-abdf2f28a0bd25a76a31b4fd2410c7a87448ed54.zip
Auto merge of #11886 - bholley:attr_refactor, r=SimonSapin
Refactor attribute handling to avoid marshalling attributes from Gecko into Servo This marshaling is slow, because Gecko stores attributes as UTF-16 and does not atomize them in all cases, and it turns out that the need for them in Servo is pretty minimal. With some refactoring across servo and rust-selectors we can fix this. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11886) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/element.rs53
1 files changed, 28 insertions, 25 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index d9535663d46..e53f7dbb77b 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -2217,6 +2217,34 @@ impl VirtualMethods for Element {
}
}
+impl<'a> ::selectors::MatchAttrGeneric for Root<Element> {
+ fn match_attr<F>(&self, attr: &AttrSelector, test: F) -> bool
+ where F: Fn(&str) -> bool
+ {
+ use ::selectors::Element;
+ let local_name = {
+ if self.is_html_element_in_html_document() {
+ &attr.lower_name
+ } else {
+ &attr.name
+ }
+ };
+ match attr.namespace {
+ NamespaceConstraint::Specific(ref ns) => {
+ self.get_attribute(ns, local_name)
+ .map_or(false, |attr| {
+ test(&attr.value())
+ })
+ },
+ NamespaceConstraint::Any => {
+ self.attrs.borrow().iter().any(|attr| {
+ attr.local_name() == local_name && test(&attr.value())
+ })
+ }
+ }
+ }
+}
+
impl<'a> ::selectors::Element for Root<Element> {
type Impl = ServoSelectorImpl;
@@ -2317,31 +2345,6 @@ impl<'a> ::selectors::Element for Root<Element> {
}
}
- fn match_attr<F>(&self, attr: &AttrSelector, test: F) -> bool
- where F: Fn(&str) -> bool
- {
- let local_name = {
- if self.is_html_element_in_html_document() {
- &attr.lower_name
- } else {
- &attr.name
- }
- };
- match attr.namespace {
- NamespaceConstraint::Specific(ref ns) => {
- self.get_attribute(ns, local_name)
- .map_or(false, |attr| {
- test(&attr.value())
- })
- },
- NamespaceConstraint::Any => {
- self.attrs.borrow().iter().any(|attr| {
- attr.local_name() == local_name && test(&attr.value())
- })
- }
- }
- }
-
fn is_html_element_in_html_document(&self) -> bool {
self.html_element_in_html_document()
}