Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stylo: Use atoms as the pseudo-element back-end. #12815

Merged
merged 12 commits into from Aug 16, 2016

stylo: Add sugar over the bitfield accessors in nsIAtom.

  • Loading branch information
emilio committed Aug 16, 2016
commit 2b3c684b373221626bab78f8119416513425294d
@@ -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>;
@@ -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.
@@ -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;
@@ -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)
}
}
@@ -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());
}
}
}
}
@@ -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))
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.