@@ -328,21 +328,38 @@ where
328
328
329
329
let current_job_id = qcx. current_query_job ( ) ;
330
330
331
- match state_lock. raw_entry_mut ( ) . from_key_hashed_nocheck ( key_hash, & key) {
332
- RawEntryMut :: Vacant ( entry) => {
331
+ match state_lock. raw_table_mut ( ) . find_or_find_insert_slot (
332
+ key_hash,
333
+ |( k, _) | * k == key,
334
+ |( k, _) | sharded:: make_hash ( k) ,
335
+ ) {
336
+ Err ( free_slot) => {
333
337
// Nothing has computed or is computing the query, so we start a new job and insert it in the
334
338
// state map.
335
339
let id = qcx. next_job_id ( ) ;
336
340
let job = QueryJob :: new ( id, span, current_job_id) ;
337
- entry. insert_hashed_nocheck ( key_hash, key, QueryResult :: Started ( job) ) ;
341
+
342
+ // SAFETY: The slot is still valid as there's
343
+ // been no mutation to the table since we hold the lock.
344
+ unsafe {
345
+ state_lock. raw_table_mut ( ) . insert_in_slot (
346
+ key_hash,
347
+ free_slot,
348
+ ( key, QueryResult :: Started ( job) ) ,
349
+ ) ;
350
+ }
338
351
339
352
// Drop the lock before we start executing the query
340
353
drop ( state_lock) ;
341
354
342
355
execute_job :: < _ , _ , INCR > ( query, qcx, state, key, key_hash, id, dep_node)
343
356
}
344
- RawEntryMut :: Occupied ( mut entry) => {
345
- match entry. get_mut ( ) {
357
+ Ok ( bucket) => {
358
+ // SAFETY: We know this bucket is still valid
359
+ // since we just got it from `find_or_find_insert_slot`.
360
+ let entry = unsafe { & mut bucket. as_mut ( ) . 1 } ;
361
+
362
+ match entry {
346
363
QueryResult :: Started ( job) => {
347
364
#[ cfg( parallel_compiler) ]
348
365
if sync:: is_dyn_thread_safe ( ) {
0 commit comments