@@ -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