Skip to content

Commit e363d04

Browse files
pitajudoprog
authored andcommitted
fix #34 entry perf due to missing inline
add clippy lint to enforce it
1 parent f55aa15 commit e363d04

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@
314314
// Useful clippy lints for no_std support
315315
clippy::std_instead_of_core,
316316
clippy::std_instead_of_alloc,
317-
clippy::alloc_instead_of_core
317+
clippy::alloc_instead_of_core,
318+
// Useful extra perf lints
319+
clippy::missing_inline_in_public_items
318320
)]
319321
// `clippy::pedantic` exceptions
320322
#![allow(

src/map.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ where
775775
/// map.remove(Key::First(true));
776776
/// assert_eq!(map.len(), 1);
777777
/// ```
778+
#[inline]
778779
pub fn len(&self) -> usize {
779780
self.storage.len()
780781
}
@@ -825,6 +826,7 @@ where
825826
/// assert_eq!(map.get(Key::Second), Some(&vec![2; 4]));
826827
/// ```
827828
#[cfg(feature = "entry")]
829+
#[inline]
828830
pub fn entry(&mut self, key: K) -> Entry<'_, K::Storage<V>, K, V>
829831
where
830832
K::Storage<V>: entry::StorageEntry<K, V>,
@@ -958,6 +960,7 @@ where
958960
K: Key + fmt::Debug,
959961
V: fmt::Debug,
960962
{
963+
#[inline]
961964
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
962965
f.debug_map().entries(self.iter()).finish()
963966
}
@@ -1167,6 +1170,7 @@ where
11671170
K: Key + serde::Serialize,
11681171
V: serde::Serialize,
11691172
{
1173+
#[inline]
11701174
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
11711175
where
11721176
S: serde::Serializer,
@@ -1189,6 +1193,7 @@ where
11891193
K: Key + serde::de::Deserialize<'de>,
11901194
V: serde::Deserialize<'de>,
11911195
{
1196+
#[inline]
11921197
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
11931198
where
11941199
D: serde::Deserializer<'de>,

src/option_bucket.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ impl<'a, T> SomeBucket<'a, T> {
116116
/// # Safety
117117
///
118118
/// Caller must guarantee that `opt` is NOT `None`.
119+
#[inline]
119120
pub unsafe fn new_unchecked(opt: &'a mut Option<T>) -> Self {
120121
debug_assert!(
121122
opt.is_some(),
@@ -129,6 +130,7 @@ impl<'a, T> SomeBucket<'a, T> {
129130
/// if `opt` is [`Some`], otherwise returns `None`.
130131
///
131132
/// For an unchecked version, see [`SomeBucket::new_unchecked`].
133+
#[inline]
132134
pub fn new(opt: &'a mut Option<T>) -> Option<Self> {
133135
if opt.is_some() {
134136
// SAFETY: If conditional ensures that `opt` is `Some`
@@ -153,6 +155,7 @@ impl<'a, T> SomeBucket<'a, T> {
153155
/// assert_eq!(hello, "Hello");
154156
/// assert_eq!(length, 13);
155157
/// ```
158+
#[inline]
156159
pub fn as_ref(&self) -> &T {
157160
// SAFETY: `outer` is guaranteed to be `Some`
158161
// by the invariants of `new_unchecked`
@@ -173,6 +176,7 @@ impl<'a, T> SomeBucket<'a, T> {
173176
/// some.as_mut().push_str(" Happy to be here.");
174177
/// assert_eq!(some.as_ref(), "Hello, world! Happy to be here.");
175178
/// ```
179+
#[inline]
176180
pub fn as_mut(&mut self) -> &mut T {
177181
// SAFETY: `outer` is guaranteed to be `Some`
178182
// by the invariants of `new_unchecked`
@@ -205,6 +209,7 @@ impl<'a, T> SomeBucket<'a, T> {
205209
/// // can not longer use `some`
206210
/// some.as_ref();
207211
/// ```
212+
#[inline]
208213
pub fn into_mut(self) -> &'a mut T {
209214
// SAFETY: `outer` is guaranteed to be `Some`
210215
// by the invariants of `new_unchecked`
@@ -226,6 +231,7 @@ impl<'a, T> SomeBucket<'a, T> {
226231
/// assert_eq!(old, 2);
227232
/// assert_eq!(x, Some(5));
228233
/// ```
234+
#[inline]
229235
pub fn replace(&mut self, value: T) -> T {
230236
core::mem::replace(self.as_mut(), value)
231237
}
@@ -243,6 +249,7 @@ impl<'a, T> SomeBucket<'a, T> {
243249
/// assert_eq!(x, None);
244250
/// assert_eq!(y, vec![1, 2]);
245251
/// ```
252+
#[inline]
246253
pub fn take(self) -> T {
247254
// SAFETY: `outer` is guaranteed to be `Some`
248255
// by the invariants of `new_unchecked`
@@ -269,6 +276,7 @@ impl<'a, T> NoneBucket<'a, T> {
269276
/// # Safety
270277
///
271278
/// Caller must guarantee that `opt` is NOT [`Some`].
279+
#[inline]
272280
pub unsafe fn new_unchecked(opt: &'a mut Option<T>) -> Self {
273281
debug_assert!(
274282
opt.is_none(),
@@ -282,6 +290,7 @@ impl<'a, T> NoneBucket<'a, T> {
282290
/// if `opt` is [`None`], otherwise returns `None`.
283291
///
284292
/// For an unchecked version, see [`NoneBucket::new_unchecked`].
293+
#[inline]
285294
pub fn new(opt: &'a mut Option<T>) -> Option<Self> {
286295
if opt.is_none() {
287296
// SAFETY: if conditional ensures that `opt` is `None`
@@ -306,6 +315,7 @@ impl<'a, T> NoneBucket<'a, T> {
306315
/// *val = 3;
307316
/// assert_eq!(opt.unwrap(), 3);
308317
/// ```
318+
#[inline]
309319
pub fn insert(self, value: T) -> &'a mut T {
310320
// SAFETY: `outer` is `None`, so there is no old value to `drop`
311321
unsafe {
@@ -344,6 +354,7 @@ impl<'a, T> OptionBucket<'a, T> {
344354
/// let some_bucket = OptionBucket::new(&mut some);
345355
/// assert!(matches!(some_bucket, OptionBucket::Some(_)));
346356
/// ```
357+
#[inline]
347358
pub fn new(opt: &'a mut Option<T>) -> Self {
348359
if opt.is_some() {
349360
// SAFETY: if conditional ensures that `opt` is `Some`

src/set.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ impl<K> fmt::Debug for Set<K>
517517
where
518518
K: Key + fmt::Debug,
519519
{
520+
#[inline]
520521
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
521522
f.debug_set().entries(self.iter()).finish()
522523
}
@@ -674,6 +675,7 @@ impl<K> serde::Serialize for Set<K>
674675
where
675676
K: Key + serde::Serialize,
676677
{
678+
#[inline]
677679
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
678680
where
679681
S: serde::Serializer,
@@ -695,6 +697,7 @@ impl<'de, K> serde::de::Deserialize<'de> for Set<K>
695697
where
696698
K: Key + serde::de::Deserialize<'de>,
697699
{
700+
#[inline]
698701
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
699702
where
700703
D: serde::Deserializer<'de>,

src/storage/option.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ where
7878
V: Clone,
7979
K::Storage<V>: Clone,
8080
{
81+
#[inline]
8182
fn clone(&self) -> Self {
8283
Self {
8384
some: self.some.clone(),
@@ -113,6 +114,7 @@ where
113114
K::Storage<V>: PartialEq,
114115
V: PartialEq,
115116
{
117+
#[inline]
116118
fn eq(&self, other: &Self) -> bool {
117119
self.none == other.none && self.some == other.some
118120
}

0 commit comments

Comments
 (0)