1
- use super :: EitherIter ;
1
+ use super :: either_iter :: EitherIter ;
2
2
use crate :: fx:: FxHashMap ;
3
3
use arrayvec:: ArrayVec ;
4
4
use std:: borrow:: Borrow ;
@@ -32,6 +32,7 @@ pub enum SsoHashMap<K, V> {
32
32
33
33
impl < K , V > SsoHashMap < K , V > {
34
34
/// Creates an empty `SsoHashMap`.
35
+ #[ inline]
35
36
pub fn new ( ) -> Self {
36
37
SsoHashMap :: Array ( ArrayVec :: new ( ) )
37
38
}
@@ -81,13 +82,15 @@ impl<K, V> SsoHashMap<K, V> {
81
82
82
83
/// An iterator visiting all key-value pairs in arbitrary order.
83
84
/// The iterator element type is `(&'a K, &'a V)`.
84
- pub fn iter ( & self ) -> impl Iterator < Item = ( & ' _ K , & ' _ V ) > {
85
+ #[ inline]
86
+ pub fn iter ( & self ) -> <& Self as IntoIterator >:: IntoIter {
85
87
self . into_iter ( )
86
88
}
87
89
88
90
/// An iterator visiting all key-value pairs in arbitrary order,
89
91
/// with mutable references to the values.
90
92
/// The iterator element type is `(&'a K, &'a mut V)`.
93
+ #[ inline]
91
94
pub fn iter_mut ( & mut self ) -> impl Iterator < Item = ( & ' _ K , & ' _ mut V ) > {
92
95
self . into_iter ( )
93
96
}
@@ -319,12 +322,14 @@ impl<K: Eq + Hash, V> SsoHashMap<K, V> {
319
322
}
320
323
321
324
/// Gets the given key's corresponding entry in the map for in-place manipulation.
325
+ #[ inline]
322
326
pub fn entry ( & mut self , key : K ) -> Entry < ' _ , K , V > {
323
327
Entry { ssomap : self , key }
324
328
}
325
329
}
326
330
327
331
impl < K , V > Default for SsoHashMap < K , V > {
332
+ #[ inline]
328
333
fn default ( ) -> Self {
329
334
Self :: new ( )
330
335
}
@@ -348,6 +353,7 @@ impl<K: Eq + Hash, V> Extend<(K, V)> for SsoHashMap<K, V> {
348
353
}
349
354
}
350
355
356
+ #[ inline]
351
357
fn extend_one ( & mut self , ( k, v) : ( K , V ) ) {
352
358
self . insert ( k, v) ;
353
359
}
@@ -375,10 +381,12 @@ where
375
381
self . extend ( iter. into_iter ( ) . map ( |( k, v) | ( k. clone ( ) , v. clone ( ) ) ) )
376
382
}
377
383
384
+ #[ inline]
378
385
fn extend_one ( & mut self , ( & k, & v) : ( & ' a K , & ' a V ) ) {
379
386
self . insert ( k, v) ;
380
387
}
381
388
389
+ #[ inline]
382
390
fn extend_reserve ( & mut self , additional : usize ) {
383
391
Extend :: < ( K , V ) > :: extend_reserve ( self , additional)
384
392
}
@@ -400,12 +408,14 @@ impl<K, V> IntoIterator for SsoHashMap<K, V> {
400
408
}
401
409
402
410
/// adapts Item of array reference iterator to Item of hashmap reference iterator.
411
+ #[ inline( always) ]
403
412
fn adapt_array_ref_it < K , V > ( pair : & ' a ( K , V ) ) -> ( & ' a K , & ' a V ) {
404
413
let ( a, b) = pair;
405
414
( a, b)
406
415
}
407
416
408
417
/// adapts Item of array mut reference iterator to Item of hashmap mut reference iterator.
418
+ #[ inline( always) ]
409
419
fn adapt_array_mut_it < K , V > ( pair : & ' a mut ( K , V ) ) -> ( & ' a K , & ' a mut V ) {
410
420
let ( a, b) = pair;
411
421
( a, b)
@@ -464,6 +474,7 @@ where
464
474
{
465
475
type Output = V ;
466
476
477
+ #[ inline]
467
478
fn index ( & self , key : & Q ) -> & V {
468
479
self . get ( key) . expect ( "no entry found for key" )
469
480
}
@@ -490,6 +501,7 @@ impl<'a, K: Eq + Hash, V> Entry<'a, K, V> {
490
501
491
502
/// Ensures a value is in the entry by inserting the default if empty, and returns
492
503
/// a mutable reference to the value in the entry.
504
+ #[ inline]
493
505
pub fn or_insert ( self , value : V ) -> & ' a mut V {
494
506
self . or_insert_with ( || value)
495
507
}
@@ -515,6 +527,7 @@ impl<'a, K: Eq + Hash, V> Entry<'a, K, V> {
515
527
}
516
528
517
529
/// Returns a reference to this entry's key.
530
+ #[ inline]
518
531
pub fn key ( & self ) -> & K {
519
532
& self . key
520
533
}
@@ -523,6 +536,7 @@ impl<'a, K: Eq + Hash, V> Entry<'a, K, V> {
523
536
impl < ' a , K : Eq + Hash , V : Default > Entry < ' a , K , V > {
524
537
/// Ensures a value is in the entry by inserting the default value if empty,
525
538
/// and returns a mutable reference to the value in the entry.
539
+ #[ inline]
526
540
pub fn or_default ( self ) -> & ' a mut V {
527
541
self . or_insert_with ( Default :: default)
528
542
}
0 commit comments