Skip to content

Commit

Permalink
stylo: Add sugar over the bitfield accessors in nsIAtom.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Aug 16, 2016
1 parent 24168f8 commit 2b3c684
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ports/geckolib/glue.rs
Expand Up @@ -264,7 +264,7 @@ pub extern "C" fn Servo_GetComputedValuesForAnonymousBox(parent_style_or_null: *
let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data);
data.flush_stylesheets();

let atom = unsafe { Atom::from_static(pseudo_tag) };
let atom = Atom::from(pseudo_tag);
let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ true);

type Helpers = ArcHelpers<ServoComputedValues, ComputedValues>;
Expand Down Expand Up @@ -293,7 +293,7 @@ pub extern "C" fn Servo_GetComputedValuesForPseudoElement(parent_style: *mut Ser
}
};

let atom = unsafe { Atom::from_static(pseudo_tag) };
let atom = Atom::from(pseudo_tag);
let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ false);

// The stylist consumes stylesheets lazily.
Expand Down
27 changes: 23 additions & 4 deletions ports/geckolib/string_cache/lib.rs
Expand Up @@ -128,6 +128,20 @@ impl WeakAtom {
String::from_utf16(self.as_slice()).unwrap()
}

#[inline]
pub fn is_static(&self) -> bool {
unsafe {
(*self.as_ptr()).mIsStatic() != 0
}
}

#[inline]
pub fn len(&self) -> u32 {
unsafe {
(*self.as_ptr()).mLength()
}
}

#[inline]
pub fn as_ptr(&self) -> *mut nsIAtom {
let const_ptr: *const nsIAtom = &self.0;
Expand Down Expand Up @@ -158,7 +172,7 @@ impl Atom {
}

#[inline]
pub unsafe fn from_static(ptr: *mut nsIAtom) -> Self {
unsafe fn from_static(ptr: *mut nsIAtom) -> Self {
Atom(ptr as *mut WeakAtom)
}
}
Expand Down Expand Up @@ -199,8 +213,10 @@ impl Clone for Atom {
impl Drop for Atom {
#[inline]
fn drop(&mut self) {
unsafe {
Gecko_ReleaseAtom(self.as_ptr());
if !self.is_static() {
unsafe {
Gecko_ReleaseAtom(self.as_ptr());
}
}
}
}
Expand Down Expand Up @@ -281,8 +297,11 @@ impl From<String> for Atom {
impl From<*mut nsIAtom> for Atom {
#[inline]
fn from(ptr: *mut nsIAtom) -> Atom {
debug_assert!(!ptr.is_null());
unsafe {
Gecko_AddRefAtom(ptr);
if (*ptr).mIsStatic() == 0 {
Gecko_AddRefAtom(ptr);
}
Atom(WeakAtom::new(ptr))
}
}
Expand Down

0 comments on commit 2b3c684

Please sign in to comment.