style: Make Element::id not clone the attribute.

This commit is contained in:
Emilio Cobos Álvarez 2018-02-24 21:49:43 +01:00
parent 98c9292ecb
commit f2efd04a5d
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
10 changed files with 46 additions and 37 deletions

View file

@ -5,6 +5,7 @@
//! A gecko snapshot, that stores the element attributes and state before they
//! change in order to properly calculate restyle hints.
use WeakAtom;
use dom::TElement;
use element_state::ElementState;
use gecko::snapshot_helpers;
@ -80,17 +81,20 @@ impl GeckoElementSnapshot {
}
/// selectors::Element::attr_matches
pub fn attr_matches(&self,
ns: &NamespaceConstraint<&Namespace>,
local_name: &Atom,
operation: &AttrSelectorOperation<&Atom>)
-> bool {
pub fn attr_matches(
&self,
ns: &NamespaceConstraint<&Namespace>,
local_name: &Atom,
operation: &AttrSelectorOperation<&Atom>,
) -> bool {
unsafe {
match *operation {
AttrSelectorOperation::Exists => {
bindings:: Gecko_SnapshotHasAttr(self,
ns.atom_or_null(),
local_name.as_ptr())
bindings:: Gecko_SnapshotHasAttr(
self,
ns.atom_or_null(),
local_name.as_ptr(),
)
}
AttrSelectorOperation::WithValue { operator, case_sensitivity, expected_value } => {
let ignore_case = match case_sensitivity {
@ -163,7 +167,7 @@ impl ElementSnapshot for GeckoElementSnapshot {
}
#[inline]
fn id_attr(&self) -> Option<Atom> {
fn id_attr(&self) -> Option<&WeakAtom> {
if !self.has_any(Flags::Id) {
return None
}
@ -172,10 +176,11 @@ impl ElementSnapshot for GeckoElementSnapshot {
bindings::Gecko_SnapshotAtomAttrValue(self, atom!("id").as_ptr())
};
// FIXME(emilio): This should assert, since this flag is exact.
if ptr.is_null() {
None
} else {
Some(Atom::from(ptr))
Some(unsafe { WeakAtom::new(ptr) })
}
}

View file

@ -1176,7 +1176,7 @@ impl<'le> TElement for GeckoElement<'le> {
// FIXME(emilio): we should probably just return a reference to the Atom.
#[inline]
fn id(&self) -> Option<Atom> {
fn id(&self) -> Option<&WeakAtom> {
if !self.has_id() {
return None;
}
@ -1185,10 +1185,12 @@ impl<'le> TElement for GeckoElement<'le> {
bindings::Gecko_AtomAttrValue(self.0, atom!("id").as_ptr())
};
// FIXME(emilio): Pretty sure the has_id flag is exact and we could
// assert here.
if ptr.is_null() {
None
} else {
Some(Atom::from(ptr))
Some(unsafe { WeakAtom::new(ptr) })
}
}