Use cached element ID in LayoutElement::get_id

This commit is contained in:
Ali Sabil 2015-08-07 12:33:06 +02:00 committed by Anthony Ramine
parent ea655ada10
commit 2e9d8a76d1
2 changed files with 9 additions and 1 deletions

View file

@ -487,7 +487,7 @@ impl<'le> ::selectors::Element for LayoutElement<'le> {
#[inline] #[inline]
fn get_id(&self) -> Option<Atom> { fn get_id(&self) -> Option<Atom> {
unsafe { unsafe {
(*self.element.unsafe_get()).get_attr_atom_for_layout(&ns!(""), &atom!("id")) (*self.element.id_attribute()).clone()
} }
} }

View file

@ -494,6 +494,7 @@ pub trait LayoutElementHelpers {
unsafe fn html_element_in_html_document_for_layout(&self) -> bool; unsafe fn html_element_in_html_document_for_layout(&self) -> bool;
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe fn has_attr_for_layout(&self, namespace: &Namespace, name: &Atom) -> bool; unsafe fn has_attr_for_layout(&self, namespace: &Namespace, name: &Atom) -> bool;
fn id_attribute(&self) -> *const Option<Atom>;
fn style_attribute(&self) -> *const Option<PropertyDeclarationBlock>; fn style_attribute(&self) -> *const Option<PropertyDeclarationBlock>;
fn local_name(&self) -> &Atom; fn local_name(&self) -> &Atom;
fn namespace(&self) -> &Namespace; fn namespace(&self) -> &Namespace;
@ -517,6 +518,13 @@ impl LayoutElementHelpers for LayoutJS<Element> {
get_attr_for_layout(&*self.unsafe_get(), namespace, name).is_some() get_attr_for_layout(&*self.unsafe_get(), namespace, name).is_some()
} }
#[allow(unsafe_code)]
fn id_attribute(&self) -> *const Option<Atom> {
unsafe {
(*self.unsafe_get()).id_attribute.borrow_for_layout()
}
}
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn style_attribute(&self) -> *const Option<PropertyDeclarationBlock> { fn style_attribute(&self) -> *const Option<PropertyDeclarationBlock> {
unsafe { unsafe {