Skip to content

Commit

Permalink
mruby-os-memsize/memsize.c: add up digit spaces for big-integers.
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Jul 21, 2022
1 parent 8bd1c56 commit c0a636c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/mruby/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ mrb_int mrb_bint_as_int(mrb_state *mrb, mrb_value x);
mrb_int mrb_bint_cmp(mrb_state *mrb, mrb_value x, mrb_value y);
void mrb_gc_free_bint(mrb_state *mrb, struct RBasic *x);
void mrb_bint_copy(mrb_state *mrb, mrb_value x, mrb_value y);
size_t mrb_bint_memsize(mrb_value x);
#endif

#endif /* MRUBY_INTERNAL_H */
7 changes: 7 additions & 0 deletions mrbgems/mruby-bigint/core/bigint.c
Original file line number Diff line number Diff line change
Expand Up @@ -1492,3 +1492,10 @@ mrb_bint_copy(mrb_state *mrb, mrb_value x, mrb_value y)
struct RBigint *b2 = RBIGINT(y);
mpz_init_set(mrb, &b->mp, &b2->mp);
}

size_t
mrb_bint_memsize(mrb_value x)
{
struct RBigint *b = RBIGINT(x);
return b->mp.sz * sizeof(mp_limb);
}
3 changes: 3 additions & 0 deletions mrbgems/mruby-os-memsize/src/memsize.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ os_memsize_of_object(mrb_state* mrb, mrb_value obj)
#endif
break;
case MRB_TT_BIGINT:
#if defined(MRB_USE_BIGINT)
size += mrb_bint_memsize(obj);
#endif
case MRB_TT_DATA:
case MRB_TT_ISTRUCT:
size += mrb_objspace_page_slot_size();
Expand Down

0 comments on commit c0a636c

Please sign in to comment.