Add performant implementations of get_id, has_class, and each_class.

This commit is contained in:
Bobby Holley 2016-05-25 11:53:53 -07:00
parent 0e6bc9f60b
commit b90b4a5e0f
2 changed files with 51 additions and 11 deletions

View file

@ -134,6 +134,10 @@ impl Atom {
self.0
}
pub unsafe fn with<F>(ptr: *mut nsIAtom, callback: &mut F) where F: FnMut(&Atom) {
callback(transmute(&ptr))
}
// Static atoms have a dummy AddRef/Release, so we don't bother calling
// AddRef() here. This would cause memory corruption with non-static atoms
// both because (a) we wouldn't hold the atom alive, and (b) we can't avoid
@ -226,3 +230,12 @@ impl From<String> for Atom {
Atom::from(&*string)
}
}
impl From<*mut nsIAtom> for Atom {
fn from(ptr: *mut nsIAtom) -> Atom {
unsafe {
Gecko_AddRefAtom(ptr);
Atom(ptr)
}
}
}