Remove outer RefCell from PyObjectRef

This commit is contained in:
Joey Hain
2019-02-25 19:01:01 -08:00
parent 027a6847e5
commit f10fa6db44
33 changed files with 380 additions and 425 deletions

View File

@@ -1,3 +1,6 @@
use std::cell::RefCell;
use std::hash::{Hash, Hasher};
use super::objbool;
use super::objint;
use super::objsequence::{
@@ -7,7 +10,6 @@ use super::objstr;
use super::objtype;
use crate::pyobject::{PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyResult, TypeProtocol};
use crate::vm::{ReprGuard, VirtualMachine};
use std::hash::{Hash, Hasher};
fn tuple_lt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(
@@ -21,11 +23,7 @@ fn tuple_lt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
let other = get_elements(other);
seq_lt(vm, &zelf, &other)?
} else {
return Err(vm.new_type_error(format!(
"Cannot compare {} and {} using '<'",
zelf.borrow(),
other.borrow()
)));
return Err(vm.new_type_error(format!("Cannot compare {} and {} using '<'", zelf, other)));
};
Ok(vm.ctx.new_bool(result))
@@ -43,11 +41,7 @@ fn tuple_gt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
let other = get_elements(other);
seq_gt(vm, &zelf, &other)?
} else {
return Err(vm.new_type_error(format!(
"Cannot compare {} and {} using '>'",
zelf.borrow(),
other.borrow()
)));
return Err(vm.new_type_error(format!("Cannot compare {} and {} using '>'", zelf, other)));
};
Ok(vm.ctx.new_bool(result))
@@ -65,11 +59,7 @@ fn tuple_ge(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
let other = get_elements(other);
seq_ge(vm, &zelf, &other)?
} else {
return Err(vm.new_type_error(format!(
"Cannot compare {} and {} using '>='",
zelf.borrow(),
other.borrow()
)));
return Err(vm.new_type_error(format!("Cannot compare {} and {} using '>='", zelf, other)));
};
Ok(vm.ctx.new_bool(result))
@@ -87,11 +77,7 @@ fn tuple_le(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
let other = get_elements(other);
seq_le(vm, &zelf, &other)?
} else {
return Err(vm.new_type_error(format!(
"Cannot compare {} and {} using '<='",
zelf.borrow(),
other.borrow()
)));
return Err(vm.new_type_error(format!("Cannot compare {} and {} using '<='", zelf, other)));
};
Ok(vm.ctx.new_bool(result))
@@ -110,11 +96,7 @@ fn tuple_add(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
let elements = e1.iter().chain(e2.iter()).cloned().collect();
Ok(vm.ctx.new_tuple(elements))
} else {
Err(vm.new_type_error(format!(
"Cannot add {} and {}",
zelf.borrow(),
other.borrow()
)))
Err(vm.new_type_error(format!("Cannot add {} and {}", zelf, other)))
}
}
@@ -193,7 +175,7 @@ fn tuple_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
);
if !objtype::issubclass(cls, &vm.ctx.tuple_type()) {
return Err(vm.new_type_error(format!("{} is not a subtype of tuple", cls.borrow())));
return Err(vm.new_type_error(format!("{} is not a subtype of tuple", cls)));
}
let elements = if let Some(iterable) = iterable {
@@ -203,7 +185,9 @@ fn tuple_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
};
Ok(PyObject::new(
PyObjectPayload::Sequence { elements },
PyObjectPayload::Sequence {
elements: RefCell::new(elements),
},
cls.clone(),
))
}