mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Optimize lookupPrefix.
This commit is contained in:
parent
44a4b7886d
commit
749598f5a0
2 changed files with 12 additions and 7 deletions
|
@ -561,7 +561,7 @@ pub trait ElementHelpers<'a> {
|
|||
fn get_important_inline_style_declaration(self, property: &Atom) -> Option<PropertyDeclaration>;
|
||||
fn serialize(self, traversal_scope: TraversalScope) -> Fallible<DOMString>;
|
||||
fn get_root_element(self) -> Temporary<Element>;
|
||||
fn lookup_prefix(self, namespace: Option<DOMString>) -> Option<DOMString>;
|
||||
fn lookup_prefix(self, namespace: Namespace) -> Option<DOMString>;
|
||||
}
|
||||
|
||||
impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
|
||||
|
@ -722,21 +722,23 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#locate-a-namespace-prefix
|
||||
fn lookup_prefix(self, namespace: Option<DOMString>) -> Option<DOMString> {
|
||||
fn lookup_prefix(self, namespace: Namespace) -> Option<DOMString> {
|
||||
for node in NodeCast::from_ref(self).inclusive_ancestors() {
|
||||
match ElementCast::to_ref(node.root().r()) {
|
||||
Some(element) => {
|
||||
// Step 1.
|
||||
if element.GetNamespaceURI() == namespace && element.GetPrefix().is_some() {
|
||||
return element.GetPrefix();
|
||||
if *element.namespace() == namespace {
|
||||
if let Some(prefix) = element.GetPrefix() {
|
||||
return Some(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
let attrs = element.Attributes().root();
|
||||
for i in 0..attrs.r().Length() {
|
||||
let attr = attrs.r().Item(i).unwrap().root();
|
||||
if attr.r().GetPrefix() == Some("xmlns".to_owned()) &&
|
||||
Some(attr.r().Value()) == namespace {
|
||||
if *attr.r().prefix() == Some(atom!("xmlns")) &&
|
||||
**attr.r().value() == *namespace.0 {
|
||||
return Some(attr.r().LocalName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ use devtools_traits::NodeInfo;
|
|||
use parse::html::parse_html_fragment;
|
||||
use script_traits::UntrustedNodeAddress;
|
||||
use util::geometry::Au;
|
||||
use util::namespace;
|
||||
use util::str::{DOMString, null_str_as_empty};
|
||||
use selectors::parser::{Selector, AttrSelector, NamespaceConstraint};
|
||||
use selectors::parser::parse_author_origin_selector_list_from_str;
|
||||
|
@ -2470,8 +2471,10 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-node-lookupprefix
|
||||
fn LookupPrefix(self, namespace: Option<DOMString>) -> Option<DOMString> {
|
||||
let namespace = namespace::from_domstring(namespace);
|
||||
|
||||
// Step 1.
|
||||
if null_str_as_empty(&namespace).is_empty() {
|
||||
if namespace == ns!("") {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue