aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/gecko_string_cache/mod.rs
diff options
context:
space:
mode:
authorXidorn Quan <me@upsuper.org>2017-05-21 13:06:31 +1000
committerXidorn Quan <me@upsuper.org>2017-05-21 18:03:47 +1000
commit2b1f7f6081073480d9382473d0bfd185d3c585d7 (patch)
treef4aa78fb1053f9d1027e89c47f6429e1d82c8168 /components/style/gecko_string_cache/mod.rs
parent1602edb04ac3cc06a71eb6349e137dce453bc191 (diff)
downloadservo-2b1f7f6081073480d9382473d0bfd185d3c585d7.tar.gz
servo-2b1f7f6081073480d9382473d0bfd185d3c585d7.zip
Add sugar for already_AddRefed and use it for conversion between Atom and nsIAtom pointer.
Diffstat (limited to 'components/style/gecko_string_cache/mod.rs')
-rw-r--r--components/style/gecko_string_cache/mod.rs36
1 files changed, 17 insertions, 19 deletions
diff --git a/components/style/gecko_string_cache/mod.rs b/components/style/gecko_string_cache/mod.rs
index fa89f5eab48..08933c053ff 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::nsIAtom;
+use gecko_bindings::structs::{already_AddRefed, nsIAtom};
use nsstring::nsAString;
use precomputed_hash::PrecomputedHash;
use std::ascii::AsciiExt;
@@ -219,24 +219,6 @@ impl Atom {
atom
}
- /// Creates an atom from a dynamic atom pointer that has already had AddRef
- /// called on it.
- #[inline]
- pub unsafe fn from_addrefed(ptr: *mut nsIAtom) -> Self {
- debug_assert!(!ptr.is_null());
- unsafe {
- Atom(WeakAtom::new(ptr))
- }
- }
-
- /// Convert this atom into an addrefed nsIAtom pointer.
- #[inline]
- pub fn into_addrefed(self) -> *mut nsIAtom {
- let ptr = self.as_ptr();
- mem::forget(self);
- ptr
- }
-
/// Return whether two atoms are ASCII-case-insensitive matches
pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool {
let a = self.as_slice();
@@ -358,3 +340,19 @@ impl From<*mut nsIAtom> for Atom {
}
}
}
+
+impl From<already_AddRefed<nsIAtom>> for Atom {
+ #[inline]
+ fn from(ptr: already_AddRefed<nsIAtom>) -> Atom {
+ unsafe { Atom(WeakAtom::new(ptr.take())) }
+ }
+}
+
+impl From<Atom> for already_AddRefed<nsIAtom> {
+ #[inline]
+ fn from(atom: Atom) -> already_AddRefed<nsIAtom> {
+ let ptr = atom.as_ptr();
+ mem::forget(atom);
+ unsafe { already_AddRefed::new_unchecked(ptr) }
+ }
+}