Skip to content

Commit

Permalink
reduce unnecessary heap allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ggiggle committed Jan 25, 2024
1 parent c50a880 commit 24fadd1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/type_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl<'a, K, V> Entry<'a, K, V> {
where
V: Send + Sync + 'static,
{
let v = self.inner.or_insert(Box::new(default));
let v = self.inner.or_insert_with(|| Box::new(default));
v.downcast_mut().unwrap()
}

Expand Down Expand Up @@ -54,12 +54,13 @@ impl<'a, K, V> Entry<'a, K, V> {
}
}

#[allow(clippy::unwrap_or_default)]
#[inline]
pub fn or_default(self) -> &'a mut V
where
V: Default + Send + Sync + 'static,
{
self.or_insert(V::default())
self.or_insert_with(V::default)
}
}

Expand Down

0 comments on commit 24fadd1

Please sign in to comment.