@@ -320,12 +320,11 @@ fn hash(key: usize, bits: u32) -> usize {
320
320
/// The returned bucket must be unlocked again in order to not cause deadlocks.
321
321
#[ inline]
322
322
fn lock_bucket ( key : usize ) -> & ' static Bucket {
323
- let mut bucket;
324
323
loop {
325
324
let hashtable = get_hashtable ( ) ;
326
325
327
326
let hash = hash ( key, hashtable. hash_bits ) ;
328
- bucket = & hashtable. entries [ hash] ;
327
+ let bucket = & hashtable. entries [ hash] ;
329
328
330
329
// Lock the bucket
331
330
bucket. mutex . lock ( ) ;
@@ -347,13 +346,12 @@ fn lock_bucket(key: usize) -> &'static Bucket {
347
346
/// The returned bucket must be unlocked again in order to not cause deadlocks.
348
347
#[ inline]
349
348
fn lock_bucket_checked ( key : & AtomicUsize ) -> ( usize , & ' static Bucket ) {
350
- let mut bucket;
351
349
loop {
352
350
let hashtable = get_hashtable ( ) ;
353
351
let current_key = key. load ( Ordering :: Relaxed ) ;
354
352
355
353
let hash = hash ( current_key, hashtable. hash_bits ) ;
356
- bucket = & hashtable. entries [ hash] ;
354
+ let bucket = & hashtable. entries [ hash] ;
357
355
358
356
// Lock the bucket
359
357
bucket. mutex . lock ( ) ;
@@ -380,18 +378,18 @@ fn lock_bucket_checked(key: &AtomicUsize) -> (usize, &'static Bucket) {
380
378
/// careful to only unlock it once in this case, always use `unlock_bucket_pair`.
381
379
#[ inline]
382
380
fn lock_bucket_pair ( key1 : usize , key2 : usize ) -> ( & ' static Bucket , & ' static Bucket ) {
383
- let mut bucket1;
384
381
loop {
385
382
let hashtable = get_hashtable ( ) ;
386
383
387
- // Get the lowest bucket first
388
384
let hash1 = hash ( key1, hashtable. hash_bits ) ;
389
385
let hash2 = hash ( key2, hashtable. hash_bits ) ;
390
- if hash1 <= hash2 {
391
- bucket1 = & hashtable. entries [ hash1] ;
386
+
387
+ // Get the bucket at the lowest hash/index first
388
+ let bucket1 = if hash1 <= hash2 {
389
+ & hashtable. entries [ hash1]
392
390
} else {
393
- bucket1 = & hashtable. entries [ hash2] ;
394
- }
391
+ & hashtable. entries [ hash2]
392
+ } ;
395
393
396
394
// Lock the first bucket
397
395
bucket1. mutex . lock ( ) ;
0 commit comments