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

Method adjust_indices

crates/vm/src/sliceable.rs:372–399  ·  view source on GitHub ↗

Equivalent to PySlice_AdjustIndices Convert for usage in indexing the underlying rust collections. Called *after __index__ has been called on the Slice which might mutate the collection.

(&self, len: usize)

Source from the content-addressed store, hash-verified

370 /// Convert for usage in indexing the underlying rust collections. Called *after*
371 /// __index__ has been called on the Slice which might mutate the collection.
372 pub fn adjust_indices(&self, len: usize) -> (Range<usize>, isize, usize) {
373 if len == 0 {
374 return (0..0, self.step, 0);
375 }
376 let range = if self.step.is_negative() {
377 let stop = if self.stop == -1 {
378 len
379 } else {
380 self.stop.saturating_add(1).saturated_at(len)
381 };
382 let start = if self.start == -1 {
383 len
384 } else {
385 self.start.saturating_add(1).saturated_at(len)
386 };
387 stop..start
388 } else {
389 self.start.saturated_at(len)..self.stop.saturated_at(len)
390 };
391
392 let (range, slice_len) = if range.start >= range.end {
393 (range.start..range.start, 0)
394 } else {
395 let slice_len = (range.end - range.start - 1) / self.step.unsigned_abs() + 1;
396 (range, slice_len)
397 };
398 (range, self.step, slice_len)
399 }
400
401 pub fn iter(&self, len: usize) -> SaturatedSliceIter {
402 SaturatedSliceIter::new(self, len)

Callers 12

getitem_by_sliceMethod · 0.80
setitem_by_sliceMethod · 0.80
subscriptMethod · 0.80
ass_subscriptMethod · 0.80
setitem_by_sliceMethod · 0.80
delitem_by_sliceMethod · 0.80
getitem_by_sliceMethod · 0.80
newMethod · 0.80
getitem_by_sliceMethod · 0.80
setitem_by_sliceMethod · 0.80
init_sliceMethod · 0.80

Calls 1

saturated_atMethod · 0.80

Tested by

no test coverage detected