mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Remove PyTuple::fast_getitem (#5863)
This commit is contained in:
@@ -1235,13 +1235,13 @@ impl AsSequence for PyDictItems {
|
||||
}
|
||||
|
||||
let zelf = PyDictItems::sequence_downcast(seq);
|
||||
let key = needle.fast_getitem(0);
|
||||
if !zelf.dict.__contains__(key.clone(), vm)? {
|
||||
let key = &needle[0];
|
||||
if !zelf.dict.__contains__(key.to_owned(), vm)? {
|
||||
return Ok(false);
|
||||
}
|
||||
let value = needle.fast_getitem(1);
|
||||
let found = zelf.dict().__getitem__(key, vm)?;
|
||||
vm.identical_or_equal(&found, &value)
|
||||
let value = &needle[1];
|
||||
let found = zelf.dict().__getitem__(key.to_owned(), vm)?;
|
||||
vm.identical_or_equal(&found, value)
|
||||
}),
|
||||
..PySequenceMethods::NOT_IMPLEMENTED
|
||||
});
|
||||
|
||||
@@ -212,7 +212,7 @@ impl PyMemoryView {
|
||||
.unpack(&bytes[pos..pos + self.desc.itemsize], vm)
|
||||
.map(|x| {
|
||||
if x.len() == 1 {
|
||||
x.fast_getitem(0)
|
||||
x[0].to_owned()
|
||||
} else {
|
||||
x.into()
|
||||
}
|
||||
@@ -1067,7 +1067,7 @@ fn format_unpack(
|
||||
) -> PyResult<PyObjectRef> {
|
||||
format_spec.unpack(bytes, vm).map(|x| {
|
||||
if x.len() == 1 {
|
||||
x.fast_getitem(0)
|
||||
x[0].to_owned()
|
||||
} else {
|
||||
x.into()
|
||||
}
|
||||
|
||||
@@ -108,12 +108,6 @@ impl_from_into_pytuple!(A, B, C, D, E);
|
||||
impl_from_into_pytuple!(A, B, C, D, E, F);
|
||||
impl_from_into_pytuple!(A, B, C, D, E, F, G);
|
||||
|
||||
impl PyTuple {
|
||||
pub(crate) fn fast_getitem(&self, idx: usize) -> PyObjectRef {
|
||||
self.elements[idx].clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub type PyTupleRef = PyRef<PyTuple>;
|
||||
|
||||
impl Constructor for PyTuple {
|
||||
|
||||
@@ -194,7 +194,7 @@ fn dedup_and_flatten_args(args: &Py<PyTuple>, vm: &VirtualMachine) -> PyTupleRef
|
||||
pub fn make_union(args: &Py<PyTuple>, vm: &VirtualMachine) -> PyObjectRef {
|
||||
let args = dedup_and_flatten_args(args, vm);
|
||||
match args.len() {
|
||||
1 => args.fast_getitem(0),
|
||||
1 => args[0].to_owned(),
|
||||
_ => PyUnion::new(args, vm).to_pyobject(vm),
|
||||
}
|
||||
}
|
||||
@@ -212,7 +212,7 @@ impl PyUnion {
|
||||
if new_args.is_empty() {
|
||||
res = make_union(&new_args, vm);
|
||||
} else {
|
||||
res = new_args.fast_getitem(0);
|
||||
res = new_args[0].to_owned();
|
||||
for arg in new_args.iter().skip(1) {
|
||||
res = vm._or(&res, arg)?;
|
||||
}
|
||||
|
||||
@@ -1667,7 +1667,7 @@ pub(super) mod types {
|
||||
.enumerate()
|
||||
{
|
||||
if location_tup_len > i {
|
||||
zelf.set_attr(attr, location_tuple.fast_getitem(i).clone(), vm)?;
|
||||
zelf.set_attr(attr, location_tuple[i].to_owned(), vm)?;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -404,14 +404,14 @@ impl PyObject {
|
||||
return Ok(false);
|
||||
}
|
||||
1 => {
|
||||
first_item = tuple.fast_getitem(0).clone();
|
||||
first_item = tuple[0].clone();
|
||||
derived = &first_item;
|
||||
continue;
|
||||
}
|
||||
_ => {
|
||||
if let Some(i) = (0..n).next() {
|
||||
for i in 0..n {
|
||||
let check = vm.with_recursion("in abstract_issubclass", || {
|
||||
tuple.fast_getitem(i).abstract_issubclass(cls, vm)
|
||||
tuple[i].abstract_issubclass(cls, vm)
|
||||
})?;
|
||||
if check {
|
||||
return Ok(true);
|
||||
|
||||
@@ -97,7 +97,7 @@ pub trait PyStructSequence: StaticType + PyClassImpl + Sized + 'static {
|
||||
class.set_attr(
|
||||
ctx.intern_str(name),
|
||||
ctx.new_readonly_getset(name, class, move |zelf: &PyTuple| {
|
||||
zelf.fast_getitem(i.into())
|
||||
zelf[i as usize].to_owned()
|
||||
})
|
||||
.into(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user