Skip to content

Commit 6b14756

Browse files
committed
Relocate vm.obj_len to obj.length
1 parent 6e6a9f6 commit 6b14756

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

stdlib/src/bisect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ mod _bisect {
7272
BisectArgs { a, x, lo, hi }: BisectArgs,
7373
vm: &VirtualMachine,
7474
) -> PyResult<usize> {
75-
let (mut lo, mut hi) = as_usize(lo, hi, vm.obj_len(&a)?, vm)?;
75+
let (mut lo, mut hi) = as_usize(lo, hi, a.length(vm)?, vm)?;
7676

7777
while lo < hi {
7878
// Handles issue 13496.
@@ -100,7 +100,7 @@ mod _bisect {
100100
BisectArgs { a, x, lo, hi }: BisectArgs,
101101
vm: &VirtualMachine,
102102
) -> PyResult<usize> {
103-
let (mut lo, mut hi) = as_usize(lo, hi, vm.obj_len(&a)?, vm)?;
103+
let (mut lo, mut hi) = as_usize(lo, hi, a.length(vm)?, vm)?;
104104

105105
while lo < hi {
106106
// Handles issue 13496.

vm/src/builtins/enumerate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl PyReverseSequenceIterator {
8888
fn length_hint(&self, vm: &VirtualMachine) -> PyResult<usize> {
8989
let internal = self.internal.lock();
9090
if let IterStatus::Active(obj) = &internal.status {
91-
if internal.position <= vm.obj_len(obj)? {
91+
if internal.position <= obj.length(vm)? {
9292
return Ok(internal.position + 1);
9393
}
9494
}

vm/src/builtins/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl PySequenceIterator {
181181
fn length_hint(&self, vm: &VirtualMachine) -> PyObjectRef {
182182
let internal = self.internal.lock();
183183
if let IterStatus::Active(obj) = &internal.status {
184-
vm.obj_len(obj)
184+
obj.length(vm)
185185
.map(|x| PyInt::from(x).into_object(vm))
186186
.unwrap_or_else(|_| vm.ctx.not_implemented())
187187
} else {

vm/src/stdlib/builtins.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ mod builtins {
424424

425425
#[pyfunction]
426426
fn len(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {
427-
vm.obj_len(&obj)
427+
obj.length(vm)
428428
}
429429

430430
#[pyfunction]
@@ -690,7 +690,7 @@ mod builtins {
690690
vm.get_method_or_type_error(obj.clone(), "__getitem__", || {
691691
"argument to reversed() must be a sequence".to_owned()
692692
})?;
693-
let len = vm.obj_len(&obj)?;
693+
let len = obj.length(vm)?;
694694
let obj_iterator = PyReverseSequenceIterator::new(obj, len);
695695
Ok(obj_iterator.into_object(vm))
696696
}

vm/src/stdlib/io.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,11 @@ mod _io {
453453
}
454454
let hint = hint as usize;
455455
let mut ret = Vec::new();
456-
let it = ArgIterable::try_from_object(vm, instance)?;
456+
let it = ArgIterable::<PyObjectRef>::try_from_object(vm, instance)?;
457457
let mut full_len = 0;
458458
for line in it.iter(vm)? {
459459
let line = line?;
460-
let line_len = vm.obj_len(&line)?;
460+
let line_len = line.length(vm)?;
461461
ret.push(line.clone());
462462
full_len += line_len;
463463
if full_len > hint {

0 commit comments

Comments
 (0)