Skip to content

Commit 8b9c4b9

Browse files
committed
Skip second lookup with synchronization disabled
1 parent ebdc942 commit 8b9c4b9

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

compiler/rustc_data_structures/src/sync/lock.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ impl<T> Lock<T> {
112112
self.data.get_mut()
113113
}
114114

115+
#[inline(always)]
116+
pub fn mode(&self) -> Mode {
117+
self.mode
118+
}
119+
115120
#[inline(always)]
116121
pub fn try_lock(&self) -> Option<LockGuard<'_, T>> {
117122
let mode = self.mode;

compiler/rustc_data_structures/src/sync/sync_table.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use horde::sync_table::Write;
88
use rustc_hash::FxBuildHasher;
99

1010
use crate::sharded::IntoPointer;
11-
use crate::sync::{DynSync, Lock, LockGuard};
11+
use crate::sync::{DynSync, Lock, LockGuard, Mode};
1212

1313
pub struct SyncTable<K, V> {
1414
// We use this lock to protect `table` instead of the internal mutex in `horde::SyncTable`
@@ -120,9 +120,11 @@ impl<K: Eq + Hash + Copy + Send> SyncTable<K, ()> {
120120

121121
let mut write = self.lock();
122122

123-
let entry = self.read(pin).get(value, Some(hash));
124-
if let Some(entry) = entry {
125-
return *entry.0;
123+
if self.lock.mode() == Mode::Sync {
124+
let entry = self.read(pin).get(value, Some(hash));
125+
if let Some(entry) = entry {
126+
return *entry.0;
127+
}
126128
}
127129

128130
let result = make();
@@ -149,9 +151,11 @@ impl<K: Eq + Hash + Copy + Send> SyncTable<K, ()> {
149151

150152
let mut write = self.lock();
151153

152-
let entry = self.read(pin).get(&value, Some(hash));
153-
if let Some(entry) = entry {
154-
return *entry.0;
154+
if self.lock.mode() == Mode::Sync {
155+
let entry = self.read(pin).get(&value, Some(hash));
156+
if let Some(entry) = entry {
157+
return *entry.0;
158+
}
155159
}
156160

157161
let result = make(value);

0 commit comments

Comments
 (0)