Skip to content

Commit 2e39e80

Browse files
committed
Fix clippy collapsible_if in find_name_in_mro cache populate
1 parent 67f72ff commit 2e39e80

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

crates/vm/src/builtins/type.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -769,28 +769,27 @@ impl PyType {
769769
// Only cache positive results. Negative results are not cached to
770770
// avoid stale entries from transient MRO walk failures during
771771
// concurrent type modifications.
772-
if let Some(ref found) = result {
773-
if assigned != 0
774-
&& !TYPE_CACHE_CLEARING.load(Ordering::Acquire)
775-
&& self.tp_version_tag.load(Ordering::Acquire) == assigned
776-
{
777-
let idx = type_cache_hash(assigned, name);
778-
let entry = &TYPE_CACHE[idx];
779-
// Invalidate first to prevent readers from seeing partial state
780-
entry.version.store(0, Ordering::Release);
781-
// Swap in new value (refcount held by cache)
782-
let new_ptr = found.clone().into_raw().as_ptr();
783-
let old_ptr = entry.value.swap(new_ptr, Ordering::Relaxed);
784-
entry
785-
.name
786-
.store(name as *const _ as *mut _, Ordering::Relaxed);
787-
// Activate entry — Release ensures value/name writes are visible
788-
entry.version.store(assigned, Ordering::Release);
789-
// Drop previous occupant (its version was already invalidated)
790-
if !old_ptr.is_null() {
791-
unsafe {
792-
drop(PyObjectRef::from_raw(NonNull::new_unchecked(old_ptr)));
793-
}
772+
if let Some(ref found) = result
773+
&& assigned != 0
774+
&& !TYPE_CACHE_CLEARING.load(Ordering::Acquire)
775+
&& self.tp_version_tag.load(Ordering::Acquire) == assigned
776+
{
777+
let idx = type_cache_hash(assigned, name);
778+
let entry = &TYPE_CACHE[idx];
779+
// Invalidate first to prevent readers from seeing partial state
780+
entry.version.store(0, Ordering::Release);
781+
// Swap in new value (refcount held by cache)
782+
let new_ptr = found.clone().into_raw().as_ptr();
783+
let old_ptr = entry.value.swap(new_ptr, Ordering::Relaxed);
784+
entry
785+
.name
786+
.store(name as *const _ as *mut _, Ordering::Relaxed);
787+
// Activate entry — Release ensures value/name writes are visible
788+
entry.version.store(assigned, Ordering::Release);
789+
// Drop previous occupant (its version was already invalidated)
790+
if !old_ptr.is_null() {
791+
unsafe {
792+
drop(PyObjectRef::from_raw(NonNull::new_unchecked(old_ptr)));
794793
}
795794
}
796795
}

0 commit comments

Comments
 (0)