Implemented bytes.__sizeof__

This commit is contained in:
Jack Park
2019-10-23 17:20:06 +09:00
parent e4bded8ca3
commit b3f25ff7ff

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) {