MCPcopy Index your code
hub / github.com/RustPython/RustPython / swap_init

Method swap_init

crates/vm/src/builtins/type.rs:303–315  ·  view source on GitHub ↗
(&self, new_init: Option<PyRef<PyFunction>>, vm: Option<&VirtualMachine>)

Source from the content-addressed store, hash-verified

301
302 #[inline]
303 fn swap_init(&self, new_init: Option<PyRef<PyFunction>>, vm: Option<&VirtualMachine>) {
304 if let Some(vm) = vm {
305 // Keep replaced refs alive for the currently executing frame, matching
306 // CPython-style "old pointer remains valid during ongoing execution"
307 // without accumulating global retired refs.
308 self.init.swap_to_temporary_refs(new_init, vm);
309 return;
310 }
311 // SAFETY: old value is moved to `retired`, so it stays alive while
312 // concurrent readers may still hold borrowed references.
313 let old = unsafe { self.init.swap(new_init) };
314 self.retire_old_function(old);
315 }
316
317 #[inline]
318 fn swap_getitem(&self, new_getitem: Option<PyRef<PyFunction>>, vm: Option<&VirtualMachine>) {

Calls 3

retire_old_functionMethod · 0.80
swapMethod · 0.45

Tested by

no test coverage detected