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

Method iter

crates/vm/src/builtins/range.rs:528–559  ·  view source on GitHub ↗
(zelf: PyRef<Self>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

526
527impl Iterable for PyRange {
528 fn iter(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult {
529 let (start, stop, step, length) = (
530 zelf.start.as_bigint(),
531 zelf.stop.as_bigint(),
532 zelf.step.as_bigint(),
533 zelf.__len__(),
534 );
535 if let (Some(start), Some(step), Some(_), Some(_)) = (
536 start.to_isize(),
537 step.to_isize(),
538 stop.to_isize(),
539 (start + step).to_isize(),
540 ) {
541 Ok(PyRangeIterator {
542 index: AtomicCell::new(0),
543 start,
544 step,
545 // Cannot fail. If start, stop and step all successfully convert to isize, then result of zelf.len will
546 // always fit in a usize.
547 length: length.to_usize().unwrap_or(0),
548 }
549 .into_pyobject(vm))
550 } else {
551 Ok(PyLongRangeIterator {
552 index: AtomicCell::new(0),
553 start: start.clone(),
554 step: step.clone(),
555 length,
556 }
557 .into_pyobject(vm))
558 }
559 }
560}
561
562impl Representable for PyRange {

Callers 1

__reduce__Method · 0.45

Calls 6

newFunction · 0.85
as_bigintMethod · 0.80
__len__Method · 0.45
into_pyobjectMethod · 0.45
to_usizeMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected