Merge pull request #1557 from xarus01/master

Implemented bytes.__sizeof__
This commit is contained in:
Noah
2019-10-23 10:57:36 -05:00
committed by GitHub

View File

@@ -1,4 +1,5 @@
use std::cell::Cell;
use std::mem::size_of;
use std::ops::Deref;
use wtf8;
@@ -149,6 +150,11 @@ impl PyBytesRef {
}
}
#[pymethod(name = "__sizeof__")]
fn sizeof(self, _vm: &VirtualMachine) -> PyResult<usize> {
Ok(size_of::<Self>() + self.inner.elements.len() * size_of::<u8>())
}
#[pymethod(name = "__add__")]
fn add(self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
if let Ok(other) = PyByteInner::try_from_object(vm, other) {