Skip to content

Commit 4b93479

Browse files
authored
Merge pull request #1557 from xarus01/master
Implemented bytes.__sizeof__
2 parents 66e11e8 + b3f25ff commit 4b93479

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

vm/src/obj/objbytes.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::cell::Cell;
2+
use std::mem::size_of;
23
use std::ops::Deref;
34

45
use wtf8;
@@ -149,6 +150,11 @@ impl PyBytesRef {
149150
}
150151
}
151152

153+
#[pymethod(name = "__sizeof__")]
154+
fn sizeof(self, _vm: &VirtualMachine) -> PyResult<usize> {
155+
Ok(size_of::<Self>() + self.inner.elements.len() * size_of::<u8>())
156+
}
157+
152158
#[pymethod(name = "__add__")]
153159
fn add(self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
154160
if let Ok(other) = PyByteInner::try_from_object(vm, other) {

0 commit comments

Comments
 (0)