Remove impl IntoPyObject for &PyObjectRef and &PyRef

they doesn't give any benefit but just hide clone
This commit is contained in:
Jeong YunWon committed 2020-08-05 14:17:01 +09:00
1 parent 61455ce261
commit ea25947b53
7 files changed
+9 -22

No files matched your search

+2 -3
View File
@@ -1,7 +1,7 @@
use crate::exceptions::PyBaseExceptionRef;
use crate::function::PyFuncArgs;
use crate::obj::{objstr, objtype};
use crate::pyobject::{IntoPyObject, ItemProtocol, PyObjectRef, PyResult, TypeProtocol};
use crate::pyobject::{ItemProtocol, PyObjectRef, PyResult, TypeProtocol};
use crate::vm::VirtualMachine;
use itertools::{Itertools, PeekingNext};
use num_bigint::{BigInt, Sign};
@@ -823,8 +823,7 @@ impl FormatString {
argument = vm.get_attribute(argument, attribute.as_str())?;
}
FieldNamePart::Index(index) => {
// TODO Implement DictKey for usize so we can pass index directly
argument = argument.get_item(&index.into_pyobject(vm), vm)?;
argument = argument.get_item(index, vm)?;
}
FieldNamePart::StringIndex(index) => {
argument = argument.get_item(&index, vm)?;
+3 -3
View File
@@ -947,7 +947,7 @@ impl ExecutingFrame<'_> {
fn execute_subscript(&mut self, vm: &VirtualMachine) -> FrameResult {
let b_ref = self.pop_value();
let a_ref = self.pop_value();
let value = a_ref.get_item(&b_ref, vm)?;
let value = a_ref.get_item(b_ref, vm)?;
self.push_value(value);
Ok(None)
}
@@ -963,7 +963,7 @@ impl ExecutingFrame<'_> {
fn execute_delete_subscript(&mut self, vm: &VirtualMachine) -> FrameResult {
let idx = self.pop_value();
let obj = self.pop_value();
obj.del_item(&idx, vm)?;
obj.del_item(idx, vm)?;
Ok(None)
}
@@ -987,7 +987,7 @@ impl ExecutingFrame<'_> {
})?;
for (key, value) in dict {
if for_call {
if map_obj.contains_key(&key, vm) {
if map_obj.contains_key(key.clone(), vm) {
let key_repr = vm.to_repr(&key)?;
let msg = format!(
"got multiple values for keyword argument {}",
+1 -1
View File
@@ -75,7 +75,7 @@ impl PyDictRef {
} else if let Some(keys) = vm.get_method(dict_obj.clone(), "keys") {
let keys = objiter::get_iter(vm, &vm.invoke(&keys?, vec![])?)?;
while let Some(key) = objiter::get_next_object(vm, &keys)? {
let val = dict_obj.get_item(&key, vm)?;
let val = dict_obj.get_item(key.clone(), vm)?;
dict.insert(vm, key, val)?;
}
} else {
+1 -1
View File
@@ -50,7 +50,7 @@ impl PyMappingProxy {
let key = PyStringRef::try_from_object(vm, key)?;
class.get_attr(key.as_str())
}
MappingProxyInner::Dict(obj) => obj.get_item(&key, vm).ok(),
MappingProxyInner::Dict(obj) => obj.get_item(key, vm).ok(),
};
Ok(opt)
}
+1 -1
View File
@@ -60,7 +60,7 @@ impl PyMemoryView {
#[pymethod(name = "__getitem__")]
fn getitem(&self, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult {
self.obj_ref.get_item(&needle, vm)
self.obj_ref.get_item(needle, vm)
}
#[pymethod(magic)]
+1 -1
View File
@@ -953,7 +953,7 @@ impl PyString {
let mut translated = String::new();
for c in self.value.chars() {
match table.get_item(&(c as u32).into_pyobject(vm), vm) {
match table.get_item((c as u32).into_pyobject(vm), vm) {
Ok(value) => {
if let Some(text) = value.payload::<PyString>() {
translated.push_str(&text.value);
-12
View File
@@ -1160,12 +1160,6 @@ impl<T> IntoPyObject for PyRef<T> {
}
}
impl<T> IntoPyObject for &PyRef<T> {
fn into_pyobject(self, _vm: &VirtualMachine) -> PyObjectRef {
self.obj.clone()
}
}
impl IntoPyObject for PyCallable {
fn into_pyobject(self, _vm: &VirtualMachine) -> PyObjectRef {
self.into_object()
@@ -1178,12 +1172,6 @@ impl IntoPyObject for PyObjectRef {
}
}
impl IntoPyObject for &PyObjectRef {
fn into_pyobject(self, _vm: &VirtualMachine) -> PyObjectRef {
self.clone()
}
}
// Allows a built-in function to return any built-in object payload without
// explicitly implementing `IntoPyObject`.
impl<T> IntoPyObject for T