@@ -414,7 +414,6 @@ fn search_hashed<K, V, M, F>(table: M, hash: SafeHash, is_match: F) -> InternalE
414
414
search_hashed_nonempty ( table, hash, is_match)
415
415
}
416
416
417
-
418
417
/// Search for a pre-hashed key when the hash map is known to be non-empty.
419
418
#[ inline]
420
419
fn search_hashed_nonempty < K , V , M , F > ( table : M , hash : SafeHash , mut is_match : F )
@@ -557,32 +556,36 @@ impl<K, V, S> HashMap<K, V, S>
557
556
}
558
557
559
558
/// Search for a key, yielding the index if it's found in the hashtable.
560
- /// If you already have the hash for the key lying around, use
561
- /// search_hashed.
559
+ /// If you already have the hash for the key lying around, or if you need an
560
+ /// InternalEntry, use search_hashed or search_hashed_nonempty .
562
561
#[ inline]
563
- fn search < ' a , Q : ?Sized > ( & ' a self , q : & Q ) -> InternalEntry < K , V , & ' a RawTable < K , V > >
562
+ fn search < ' a , Q : ?Sized > ( & ' a self , q : & Q )
563
+ -> Option < FullBucket < K , V , & ' a RawTable < K , V > > >
564
564
where K : Borrow < Q > ,
565
565
Q : Eq + Hash
566
566
{
567
- if self . table . capacity ( ) != 0 {
568
- let hash = self . make_hash ( q) ;
569
- search_hashed_nonempty ( & self . table , hash, |k| q. eq ( k. borrow ( ) ) )
570
- } else {
571
- InternalEntry :: TableIsEmpty
567
+ if !self . is_empty ( ) {
568
+ return None ;
572
569
}
570
+
571
+ let hash = self . make_hash ( q) ;
572
+ search_hashed_nonempty ( & self . table , hash, |k| q. eq ( k. borrow ( ) ) )
573
+ . into_occupied_bucket ( )
573
574
}
574
575
575
576
#[ inline]
576
- fn search_mut < ' a , Q : ?Sized > ( & ' a mut self , q : & Q ) -> InternalEntry < K , V , & ' a mut RawTable < K , V > >
577
+ fn search_mut < ' a , Q : ?Sized > ( & ' a mut self , q : & Q )
578
+ -> Option < FullBucket < K , V , & ' a mut RawTable < K , V > > >
577
579
where K : Borrow < Q > ,
578
580
Q : Eq + Hash
579
581
{
580
- if self . table . capacity ( ) != 0 {
581
- let hash = self . make_hash ( q) ;
582
- search_hashed_nonempty ( & mut self . table , hash, |k| q. eq ( k. borrow ( ) ) )
583
- } else {
584
- InternalEntry :: TableIsEmpty
582
+ if self . is_empty ( ) {
583
+ return None ;
585
584
}
585
+
586
+ let hash = self . make_hash ( q) ;
587
+ search_hashed_nonempty ( & mut self . table , hash, |k| q. eq ( k. borrow ( ) ) )
588
+ . into_occupied_bucket ( )
586
589
}
587
590
588
591
// The caller should ensure that invariants by Robin Hood Hashing hold
@@ -1140,7 +1143,7 @@ impl<K, V, S> HashMap<K, V, S>
1140
1143
where K : Borrow < Q > ,
1141
1144
Q : Hash + Eq
1142
1145
{
1143
- self . search ( k) . into_occupied_bucket ( ) . map ( |bucket| bucket. into_refs ( ) . 1 )
1146
+ self . search ( k) . map ( |bucket| bucket. into_refs ( ) . 1 )
1144
1147
}
1145
1148
1146
1149
/// Returns true if the map contains a value for the specified key.
@@ -1167,7 +1170,7 @@ impl<K, V, S> HashMap<K, V, S>
1167
1170
where K : Borrow < Q > ,
1168
1171
Q : Hash + Eq
1169
1172
{
1170
- self . search ( k) . into_occupied_bucket ( ) . is_some ( )
1173
+ self . search ( k) . is_some ( )
1171
1174
}
1172
1175
1173
1176
/// Returns a mutable reference to the value corresponding to the key.
@@ -1196,7 +1199,7 @@ impl<K, V, S> HashMap<K, V, S>
1196
1199
where K : Borrow < Q > ,
1197
1200
Q : Hash + Eq
1198
1201
{
1199
- self . search_mut ( k) . into_occupied_bucket ( ) . map ( |bucket| bucket. into_mut_refs ( ) . 1 )
1202
+ self . search_mut ( k) . map ( |bucket| bucket. into_mut_refs ( ) . 1 )
1200
1203
}
1201
1204
1202
1205
/// Inserts a key-value pair into the map.
@@ -1256,11 +1259,7 @@ impl<K, V, S> HashMap<K, V, S>
1256
1259
where K : Borrow < Q > ,
1257
1260
Q : Hash + Eq
1258
1261
{
1259
- if self . table . size ( ) == 0 {
1260
- return None ;
1261
- }
1262
-
1263
- self . search_mut ( k) . into_occupied_bucket ( ) . map ( |bucket| pop_internal ( bucket) . 1 )
1262
+ self . search_mut ( k) . map ( |bucket| pop_internal ( bucket) . 1 )
1264
1263
}
1265
1264
1266
1265
/// Removes a key from the map, returning the stored key and value if the
@@ -1296,7 +1295,6 @@ impl<K, V, S> HashMap<K, V, S>
1296
1295
}
1297
1296
1298
1297
self . search_mut ( k)
1299
- . into_occupied_bucket ( )
1300
1298
. map ( |bucket| {
1301
1299
let ( k, v, _) = pop_internal ( bucket) ;
1302
1300
( k, v)
@@ -2654,15 +2652,11 @@ impl<K, S, Q: ?Sized> super::Recover<Q> for HashMap<K, (), S>
2654
2652
2655
2653
#[ inline]
2656
2654
fn get ( & self , key : & Q ) -> Option < & K > {
2657
- self . search ( key) . into_occupied_bucket ( ) . map ( |bucket| bucket. into_refs ( ) . 0 )
2655
+ self . search ( key) . map ( |bucket| bucket. into_refs ( ) . 0 )
2658
2656
}
2659
2657
2660
2658
fn take ( & mut self , key : & Q ) -> Option < K > {
2661
- if self . table . size ( ) == 0 {
2662
- return None ;
2663
- }
2664
-
2665
- self . search_mut ( key) . into_occupied_bucket ( ) . map ( |bucket| pop_internal ( bucket) . 0 )
2659
+ self . search_mut ( key) . map ( |bucket| pop_internal ( bucket) . 0 )
2666
2660
}
2667
2661
2668
2662
#[ inline]
0 commit comments