mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Introduce nsStaticAtom.
It's a sub-class of nsAtom, useful for cases where you know you are dealing exclusively with static atoms. The nice thing about it is that you can use raw nsStaticAtom pointers instead of RefPtr<>. (In fact, the AddRef/Release implementations ensure that we'll crash if we use RefPtr<nsStaticAtom>.)
This commit is contained in:
parent
de7595f16f
commit
5866b820e0
5 changed files with 12525 additions and 12503 deletions
|
@ -10,7 +10,7 @@ use gecko_bindings::bindings::Gecko_AddRefAtom;
|
|||
use gecko_bindings::bindings::Gecko_Atomize;
|
||||
use gecko_bindings::bindings::Gecko_Atomize16;
|
||||
use gecko_bindings::bindings::Gecko_ReleaseAtom;
|
||||
use gecko_bindings::structs::{nsAtom, nsAtom_AtomKind};
|
||||
use gecko_bindings::structs::{nsAtom, nsAtom_AtomKind, nsStaticAtom};
|
||||
use nsstring::{nsAString, nsStr};
|
||||
use precomputed_hash::PrecomputedHash;
|
||||
use std::ascii::AsciiExt;
|
||||
|
@ -254,7 +254,7 @@ impl Atom {
|
|||
/// that way, now we have sugar for is_static, creating atoms using
|
||||
/// Atom::from should involve almost no overhead.
|
||||
#[inline]
|
||||
unsafe fn from_static(ptr: *mut nsAtom) -> Self {
|
||||
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!");
|
||||
|
@ -389,4 +389,14 @@ impl From<*mut nsAtom> for Atom {
|
|||
}
|
||||
}
|
||||
|
||||
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