Report better size numbers for lists, dicts, C types
This commit is contained in:
parent
9fe1e92c45
commit
e4df06c85f
13
src/vm.c
13
src/vm.c
@ -980,7 +980,18 @@ static KrkValue krk_getsize(int argc, KrkValue argv[]) {
|
||||
}
|
||||
case OBJ_INSTANCE: {
|
||||
KrkInstance * self = AS_INSTANCE(argv[0]);
|
||||
mySize += sizeof(KrkInstance) + sizeof(KrkTableEntry) * self->fields.capacity;
|
||||
mySize += sizeof(KrkTableEntry) * self->fields.capacity;
|
||||
KrkClass * type = krk_getType(argv[0]);
|
||||
if (type->allocSize) {
|
||||
mySize += type->allocSize;
|
||||
} else {
|
||||
mySize += sizeof(KrkInstance);
|
||||
}
|
||||
if (krk_isInstanceOf(argv[0], vm.baseClasses.listClass)) {
|
||||
mySize += sizeof(KrkValue) * AS_LIST(argv[0])->capacity;
|
||||
} else if (krk_isInstanceOf(argv[0], vm.baseClasses.dictClass)) {
|
||||
mySize += sizeof(KrkTableEntry) * AS_DICT(argv[0])->capacity;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case OBJ_CLASS: {
|
||||
|
Loading…
Reference in New Issue
Block a user