Merge pull request #722 from RustPython/joey/unboxed-payload-2

Remove Box from PyObject
This commit is contained in:
Joey
2019-03-22 20:29:36 -07:00
committed by GitHub
5 changed files with 69 additions and 50 deletions

View File

@@ -35,12 +35,6 @@ impl PyValue for PyClass {
}
}
impl IdProtocol for PyClassRef {
fn get_id(&self) -> usize {
self.as_object().get_id()
}
}
impl TypeProtocol for PyClassRef {
fn type_ref(&self) -> &PyObjectRef {
&self.as_object().type_ref()
@@ -335,10 +329,7 @@ fn take_next_base(mut bases: Vec<Vec<PyClassRef>>) -> Option<(PyClassRef, Vec<Ve
for base in &bases {
let head = base[0].clone();
if !(&bases)
.iter()
.any(|x| x[1..].iter().any(|x| x.get_id() == head.get_id()))
{
if !(&bases).iter().any(|x| x[1..].iter().any(|x| x.is(&head))) {
next = Some(head);
break;
}
@@ -346,7 +337,7 @@ fn take_next_base(mut bases: Vec<Vec<PyClassRef>>) -> Option<(PyClassRef, Vec<Ve
if let Some(head) = next {
for item in &mut bases {
if item[0].get_id() == head.get_id() {
if item[0].is(&head) {
item.remove(0);
}
}
@@ -382,10 +373,10 @@ pub fn new(
let mros = bases.into_iter().map(|x| _mro(&x)).collect();
let mro = linearise_mro(mros).unwrap();
Ok(PyObject {
payload: Box::new(PyClass {
payload: PyClass {
name: String::from(name),
mro,
}),
},
dict: Some(RefCell::new(dict)),
typ,
}

View File

@@ -1,13 +1,13 @@
use crate::obj::objtype::PyClassRef;
use crate::pyobject::PyValue;
use crate::pyobject::{PyContext, PyObject, PyObjectRef, PyRef, PyResult};
use crate::pyobject::{PyContext, PyObject, PyObjectPayload, PyObjectRef, PyRef, PyResult};
use crate::vm::VirtualMachine;
use std::rc::{Rc, Weak};
#[derive(Debug)]
pub struct PyWeak {
referent: Weak<PyObject>,
referent: Weak<PyObject<dyn PyObjectPayload>>,
}
impl PyWeak {