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

Method _to_list

crates/vm/src/builtins/memory.rs:294–322  ·  view source on GitHub ↗
(
        &self,
        bytes: &[u8],
        mut index: isize,
        dim: usize,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

292 }
293
294 fn _to_list(
295 &self,
296 bytes: &[u8],
297 mut index: isize,
298 dim: usize,
299 vm: &VirtualMachine,
300 ) -> PyResult<PyListRef> {
301 let (shape, stride, suboffset) = self.desc.dim_desc[dim];
302 if dim + 1 == self.desc.ndim() {
303 let mut v = Vec::with_capacity(shape);
304 for _ in 0..shape {
305 let pos = index + suboffset;
306 let pos = (pos + self.start as isize) as usize;
307 let obj =
308 format_unpack(&self.format_spec, &bytes[pos..pos + self.desc.itemsize], vm)?;
309 v.push(obj);
310 index += stride;
311 }
312 return Ok(vm.ctx.new_list(v));
313 }
314
315 let mut v = Vec::with_capacity(shape);
316 for _ in 0..shape {
317 let obj = self._to_list(bytes, index + suboffset, dim + 1, vm)?.into();
318 v.push(obj);
319 index += stride;
320 }
321 Ok(vm.ctx.new_list(v))
322 }
323
324 fn eq(zelf: &Py<Self>, other: &PyObject, vm: &VirtualMachine) -> PyResult<bool> {
325 if zelf.is(other) {

Callers 1

tolistMethod · 0.80

Calls 4

format_unpackFunction · 0.85
new_listMethod · 0.80
ndimMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected