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

Method getitem_by_slice

crates/stdlib/src/mmap.rs:1483–1512  ·  view source on GitHub ↗
(
            &self,
            slice: &SaturatedSlice,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

1481 }
1482
1483 fn getitem_by_slice(
1484 &self,
1485 slice: &SaturatedSlice,
1486 vm: &VirtualMachine,
1487 ) -> PyResult<PyObjectRef> {
1488 let (range, step, slice_len) = slice.adjust_indices(self.__len__());
1489
1490 let mmap = self.check_valid(vm)?;
1491 let slice_data = mmap.deref().as_ref().unwrap().as_slice();
1492
1493 if slice_len == 0 {
1494 return Ok(PyBytes::from(vec![]).into_ref(&vm.ctx).into());
1495 } else if step == 1 {
1496 return Ok(PyBytes::from(slice_data[range].to_vec())
1497 .into_ref(&vm.ctx)
1498 .into());
1499 }
1500
1501 let mut result_buf = Vec::with_capacity(slice_len);
1502 if step.is_negative() {
1503 for i in range.rev().step_by(step.unsigned_abs()) {
1504 result_buf.push(slice_data[i]);
1505 }
1506 } else {
1507 for i in range.step_by(step.unsigned_abs()) {
1508 result_buf.push(slice_data[i]);
1509 }
1510 }
1511 Ok(PyBytes::from(result_buf).into_ref(&vm.ctx).into())
1512 }
1513
1514 fn getitem_inner(&self, needle: &PyObject, vm: &VirtualMachine) -> PyResult<PyObjectRef> {
1515 match SequenceIndex::try_from_borrowed_object(vm, needle, "mmap")? {

Callers 3

getitem_innerMethod · 0.45
getitem_innerMethod · 0.45
subscriptMethod · 0.45

Calls 11

adjust_indicesMethod · 0.80
check_validMethod · 0.80
to_vecMethod · 0.80
__len__Method · 0.45
as_sliceMethod · 0.45
unwrapMethod · 0.45
as_refMethod · 0.45
derefMethod · 0.45
into_refMethod · 0.45
revMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected