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

Method materialize_to_heap

crates/vm/src/frame.rs:203–214  ·  view source on GitHub ↗

Migrate data-stack-backed storage to the heap, preserving all values. Returns the data stack base pointer for `DataStack::pop()`. Returns `None` if already heap-backed.

(&mut self)

Source from the content-addressed store, hash-verified

201 /// Returns the data stack base pointer for `DataStack::pop()`.
202 /// Returns `None` if already heap-backed.
203 fn materialize_to_heap(&mut self) -> Option<*mut u8> {
204 if let LocalsPlusData::DataStack { ptr, capacity } = &self.data {
205 let base = *ptr as *mut u8;
206 let heap_data = unsafe { core::slice::from_raw_parts(*ptr, *capacity) }
207 .to_vec()
208 .into_boxed_slice();
209 self.data = LocalsPlusData::Heap(heap_data);
210 Some(base)
211 } else {
212 None
213 }
214 }
215
216 /// Drop all contained values without freeing the backing storage.
217 fn drop_values(&mut self) {

Callers 1

Calls 3

HeapClass · 0.85
to_vecMethod · 0.80
SomeClass · 0.50

Tested by

no test coverage detected