diff options
author | Nicholas Nethercote <nnethercote@mozilla.com> | 2017-10-27 14:42:55 +1100 |
---|---|---|
committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2017-10-27 20:33:40 +1100 |
commit | 5866b820e0d7d7f496a27726cb77de9302655abf (patch) | |
tree | c425d9021c97d2cb49fae819b05dcbbfa7086fb9 /components/style/gecko_string_cache/mod.rs | |
parent | de7595f16fa41c32ca5654aef53c60ad19bb108a (diff) | |
download | servo-5866b820e0d7d7f496a27726cb77de9302655abf.tar.gz servo-5866b820e0d7d7f496a27726cb77de9302655abf.zip |
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>.)
Diffstat (limited to 'components/style/gecko_string_cache/mod.rs')
-rw-r--r-- | components/style/gecko_string_cache/mod.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/components/style/gecko_string_cache/mod.rs b/components/style/gecko_string_cache/mod.rs index 8346c7491f2..14e7ef0c143 100644 --- a/components/style/gecko_string_cache/mod.rs +++ b/components/style/gecko_string_cache/mod.rs @@ -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); |