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

Method getitem_by_slice

crates/vm/src/sliceable.rs:185–203  ·  view source on GitHub ↗
(
        &self,
        _vm: &VirtualMachine,
        slice: SaturatedSlice,
    )

Source from the content-addressed store, hash-verified

183 }
184
185 fn getitem_by_slice(
186 &self,
187 _vm: &VirtualMachine,
188 slice: SaturatedSlice,
189 ) -> PyResult<Self::Sliced> {
190 let (range, step, slice_len) = slice.adjust_indices(self.len());
191 let sliced = if slice_len == 0 {
192 Self::empty()
193 } else if step == 1 {
194 self.do_slice(range)
195 } else if step == -1 {
196 self.do_slice_reverse(range)
197 } else if step.is_positive() {
198 self.do_stepped_slice(range, step.unsigned_abs())
199 } else {
200 self.do_stepped_slice_reverse(range, step.unsigned_abs())
201 };
202 Ok(sliced)
203 }
204
205 fn getitem_by_index(&self, vm: &VirtualMachine, index: isize) -> PyResult<Self::Item> {
206 let pos = self

Callers

nothing calls this directly

Implementers 2

sliceable.rscrates/vm/src/sliceable.rs
str.rscrates/vm/src/builtins/str.rs

Calls 6

adjust_indicesMethod · 0.80
lenMethod · 0.45
do_sliceMethod · 0.45
do_slice_reverseMethod · 0.45
do_stepped_sliceMethod · 0.45

Tested by

no test coverage detected