@@ -12,6 +12,8 @@ use crate::pyobject::{
12
12
} ;
13
13
use crate :: vm:: { ReprGuard , VirtualMachine } ;
14
14
15
+ use std:: mem:: size_of;
16
+
15
17
pub type DictContentType = dictdatatype:: Dict ;
16
18
17
19
#[ derive( Default ) ]
@@ -154,6 +156,10 @@ impl PyDictRef {
154
156
self . entries . borrow ( ) . len ( )
155
157
}
156
158
159
+ fn sizeof ( self , _vm : & VirtualMachine ) -> usize {
160
+ size_of :: < Self > ( ) + self . entries . borrow ( ) . sizeof ( )
161
+ }
162
+
157
163
fn repr ( self , vm : & VirtualMachine ) -> PyResult < String > {
158
164
let s = if let Some ( _guard) = ReprGuard :: enter ( self . as_object ( ) ) {
159
165
let mut str_parts = vec ! [ ] ;
@@ -576,6 +582,7 @@ pub fn init(context: &PyContext) {
576
582
extend_class ! ( context, & context. types. dict_type, {
577
583
"__bool__" => context. new_rustfunc( PyDictRef :: bool ) ,
578
584
"__len__" => context. new_rustfunc( PyDictRef :: len) ,
585
+ "__sizeof__" => context. new_rustfunc( PyDictRef :: sizeof) ,
579
586
"__contains__" => context. new_rustfunc( PyDictRef :: contains) ,
580
587
"__delitem__" => context. new_rustfunc( PyDictRef :: inner_delitem) ,
581
588
"__eq__" => context. new_rustfunc( PyDictRef :: eq) ,
0 commit comments