mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
parent
52205e8483
commit
55e2cd5dc3
7 changed files with 85 additions and 100 deletions
|
@ -99,7 +99,9 @@ impl WeakAtom {
|
|||
/// Clone this atom, bumping the refcount if the atom is not static.
|
||||
#[inline]
|
||||
pub fn clone(&self) -> Atom {
|
||||
Atom::from(self.as_ptr())
|
||||
unsafe {
|
||||
Atom::from_raw(self.as_ptr())
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the atom hash.
|
||||
|
@ -267,15 +269,25 @@ impl Atom {
|
|||
///
|
||||
/// Right now it's only used by the atom macro, and ideally it should keep
|
||||
/// that way, now we have sugar for is_static, creating atoms using
|
||||
/// Atom::from should involve almost no overhead.
|
||||
/// Atom::from_raw should involve almost no overhead.
|
||||
#[inline]
|
||||
unsafe fn from_static(ptr: *mut nsStaticAtom) -> Self {
|
||||
pub unsafe fn from_static(ptr: *mut nsStaticAtom) -> Self {
|
||||
let atom = Atom(ptr as *mut WeakAtom);
|
||||
debug_assert!(atom.is_static(),
|
||||
"Called from_static for a non-static atom!");
|
||||
atom
|
||||
}
|
||||
|
||||
/// Creates an atom from an atom pointer.
|
||||
#[inline(always)]
|
||||
pub unsafe fn from_raw(ptr: *mut nsAtom) -> Self {
|
||||
let atom = Atom(ptr as *mut WeakAtom);
|
||||
if !atom.is_static() {
|
||||
Gecko_AddRefAtom(ptr);
|
||||
}
|
||||
atom
|
||||
}
|
||||
|
||||
/// Creates an atom from a dynamic atom pointer that has already had AddRef
|
||||
/// called on it.
|
||||
#[inline]
|
||||
|
@ -308,7 +320,9 @@ impl Hash for WeakAtom {
|
|||
impl Clone for Atom {
|
||||
#[inline(always)]
|
||||
fn clone(&self) -> Atom {
|
||||
Atom::from(self.as_ptr())
|
||||
unsafe {
|
||||
Atom::from_raw(self.as_ptr())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -388,28 +402,4 @@ impl From<String> for Atom {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<*mut nsAtom> for Atom {
|
||||
#[inline]
|
||||
fn from(ptr: *mut nsAtom) -> Atom {
|
||||
assert!(!ptr.is_null());
|
||||
unsafe {
|
||||
let ret = Atom(WeakAtom::new(ptr));
|
||||
if !ret.is_static() {
|
||||
Gecko_AddRefAtom(ptr);
|
||||
}
|
||||
ret
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<*mut nsStaticAtom> for Atom {
|
||||
#[inline]
|
||||
fn from(ptr: *mut nsStaticAtom) -> Atom {
|
||||
assert!(!ptr.is_null());
|
||||
unsafe {
|
||||
Atom::from_static(ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
malloc_size_of_is_0!(Atom);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue