Skip to content

Commit 4ebecc0

Browse files
authored
Remove PyTuple::fast_getitem (RustPython#5863)
1 parent 07a04ac commit 4ebecc0

File tree

7 files changed

+14
-20
lines changed

7 files changed

+14
-20
lines changed

vm/src/builtins/dict.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,13 +1235,13 @@ impl AsSequence for PyDictItems {
12351235
}
12361236

12371237
let zelf = PyDictItems::sequence_downcast(seq);
1238-
let key = needle.fast_getitem(0);
1239-
if !zelf.dict.__contains__(key.clone(), vm)? {
1238+
let key = &needle[0];
1239+
if !zelf.dict.__contains__(key.to_owned(), vm)? {
12401240
return Ok(false);
12411241
}
1242-
let value = needle.fast_getitem(1);
1243-
let found = zelf.dict().__getitem__(key, vm)?;
1244-
vm.identical_or_equal(&found, &value)
1242+
let value = &needle[1];
1243+
let found = zelf.dict().__getitem__(key.to_owned(), vm)?;
1244+
vm.identical_or_equal(&found, value)
12451245
}),
12461246
..PySequenceMethods::NOT_IMPLEMENTED
12471247
});

vm/src/builtins/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl PyMemoryView {
212212
.unpack(&bytes[pos..pos + self.desc.itemsize], vm)
213213
.map(|x| {
214214
if x.len() == 1 {
215-
x.fast_getitem(0)
215+
x[0].to_owned()
216216
} else {
217217
x.into()
218218
}
@@ -1067,7 +1067,7 @@ fn format_unpack(
10671067
) -> PyResult<PyObjectRef> {
10681068
format_spec.unpack(bytes, vm).map(|x| {
10691069
if x.len() == 1 {
1070-
x.fast_getitem(0)
1070+
x[0].to_owned()
10711071
} else {
10721072
x.into()
10731073
}

vm/src/builtins/tuple.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ impl_from_into_pytuple!(A, B, C, D, E);
108108
impl_from_into_pytuple!(A, B, C, D, E, F);
109109
impl_from_into_pytuple!(A, B, C, D, E, F, G);
110110

111-
impl PyTuple {
112-
pub(crate) fn fast_getitem(&self, idx: usize) -> PyObjectRef {
113-
self.elements[idx].clone()
114-
}
115-
}
116-
117111
pub type PyTupleRef = PyRef<PyTuple>;
118112

119113
impl Constructor for PyTuple {

vm/src/builtins/union.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ fn dedup_and_flatten_args(args: &Py<PyTuple>, vm: &VirtualMachine) -> PyTupleRef
194194
pub fn make_union(args: &Py<PyTuple>, vm: &VirtualMachine) -> PyObjectRef {
195195
let args = dedup_and_flatten_args(args, vm);
196196
match args.len() {
197-
1 => args.fast_getitem(0),
197+
1 => args[0].to_owned(),
198198
_ => PyUnion::new(args, vm).to_pyobject(vm),
199199
}
200200
}
@@ -212,7 +212,7 @@ impl PyUnion {
212212
if new_args.is_empty() {
213213
res = make_union(&new_args, vm);
214214
} else {
215-
res = new_args.fast_getitem(0);
215+
res = new_args[0].to_owned();
216216
for arg in new_args.iter().skip(1) {
217217
res = vm._or(&res, arg)?;
218218
}

vm/src/exceptions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ pub(super) mod types {
16671667
.enumerate()
16681668
{
16691669
if location_tup_len > i {
1670-
zelf.set_attr(attr, location_tuple.fast_getitem(i).clone(), vm)?;
1670+
zelf.set_attr(attr, location_tuple[i].to_owned(), vm)?;
16711671
} else {
16721672
break;
16731673
}

vm/src/protocol/object.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,14 +404,14 @@ impl PyObject {
404404
return Ok(false);
405405
}
406406
1 => {
407-
first_item = tuple.fast_getitem(0).clone();
407+
first_item = tuple[0].clone();
408408
derived = &first_item;
409409
continue;
410410
}
411411
_ => {
412-
if let Some(i) = (0..n).next() {
412+
for i in 0..n {
413413
let check = vm.with_recursion("in abstract_issubclass", || {
414-
tuple.fast_getitem(i).abstract_issubclass(cls, vm)
414+
tuple[i].abstract_issubclass(cls, vm)
415415
})?;
416416
if check {
417417
return Ok(true);

vm/src/types/structseq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub trait PyStructSequence: StaticType + PyClassImpl + Sized + 'static {
9797
class.set_attr(
9898
ctx.intern_str(name),
9999
ctx.new_readonly_getset(name, class, move |zelf: &PyTuple| {
100-
zelf.fast_getitem(i.into())
100+
zelf[i as usize].to_owned()
101101
})
102102
.into(),
103103
);

0 commit comments

Comments
 (0)