perf(header): optimize when inserting a new type header

This commit is contained in:
Sean McArthur
2017-06-23 18:49:18 -07:00
parent 7369fe649f
commit 7d122bd15f
3 changed files with 59 additions and 8 deletions

View File

@@ -58,6 +58,11 @@ impl<V: ?Sized + Any + 'static> PtrMapCell<V> {
PtrMapCell(UnsafeCell::new(PtrMap::Empty))
}
#[inline]
pub fn with_one(key: TypeId, val: Box<V>) -> PtrMapCell<V> {
PtrMapCell(UnsafeCell::new(PtrMap::One(key, val)))
}
#[inline]
pub fn get(&self, key: TypeId) -> Option<&V> {
let map = unsafe { &*self.0.get() };