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

Method get

crates/vm/src/builtins/range.rs:150–183  ·  view source on GitHub ↗
(&self, index: &BigInt)

Source from the content-addressed store, hash-verified

148
149 #[inline]
150 pub fn get(&self, index: &BigInt) -> Option<BigInt> {
151 let start = self.start.as_bigint();
152 let step = self.step.as_bigint();
153 let stop = self.stop.as_bigint();
154 if self.is_empty() {
155 return None;
156 }
157
158 if index.is_negative() {
159 let length = self.compute_length();
160 let index: BigInt = &length + index;
161 if index.is_negative() {
162 return None;
163 }
164
165 Some(if step.is_one() {
166 start + index
167 } else {
168 start + step * index
169 })
170 } else {
171 let index = if step.is_one() {
172 start + index
173 } else {
174 start + step * index
175 };
176
177 if (step.is_positive() && stop > &index) || (step.is_negative() && stop < &index) {
178 Some(index)
179 } else {
180 None
181 }
182 }
183 }
184
185 #[inline]
186 fn compute_length(&self) -> BigInt {

Callers 15

nextMethod · 0.45
nextMethod · 0.45
__getitem__Method · 0.45
repr_argMethod · 0.45
hashMethod · 0.45
nextMethod · 0.45
fast_nextMethod · 0.45
nextMethod · 0.45
mark_linesFunction · 0.45
f_linenoMethod · 0.45
set_f_linenoMethod · 0.45
do_getMethod · 0.45

Calls 4

as_bigintMethod · 0.80
compute_lengthMethod · 0.80
SomeClass · 0.50
is_emptyMethod · 0.45

Tested by

no test coverage detected