perf(header): optimize when inserting a new type header
This commit is contained in:
@@ -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() };
|
||||
|
||||
@@ -23,12 +23,11 @@ impl Item {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new_typed(ty: Box<Header + Send + Sync>) -> Item {
|
||||
let map = PtrMapCell::new();
|
||||
unsafe { map.insert((*ty).get_type(), ty); }
|
||||
|
||||
pub fn new_typed<H: Header>(val: H) -> Item {
|
||||
Item {
|
||||
raw: OptCell::new(None),
|
||||
typed: map,
|
||||
typed: PtrMapCell::with_one(TypeId::of::<H>(), Box::new(val)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user