diff options
author | Lourens Naudé <lourens@bearmetal.eu> | 2019-04-22 23:24:52 +0100 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-23 16:22:34 +0900 |
commit | 90c4bd2d2bd10b19c2b09834396553742bc7e8a4 (patch) | |
tree | b28ee0776163ca2fede687cee82547a202c3e494 /node.c | |
parent | ab087ecb4dd21ea5f7d1cbadd8298f2f1a3c9ce9 (diff) | |
download | ruby-90c4bd2d2bd10b19c2b09834396553742bc7e8a4.tar.gz |
Let memory sizes of the various IMEMO object types be reflected correctly
[Feature #15805]
Closes: https://github.com/ruby/ruby/pull/2140
Diffstat (limited to 'node.c')
-rw-r--r-- | node.c | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -12,6 +12,8 @@ #include "ruby/ruby.h" #include "vm_core.h" +#define NODE_BUF_DEFAULT_LEN 16 + #define A(str) rb_str_cat2(buf, (str)) #define AR(str) rb_str_concat(buf, (str)) @@ -1122,9 +1124,9 @@ struct node_buffer_struct { static node_buffer_t * rb_node_buffer_new(void) { - node_buffer_t *nb = xmalloc(sizeof(node_buffer_t) + offsetof(node_buffer_elem_t, buf) + 16 * sizeof(NODE)); + node_buffer_t *nb = xmalloc(sizeof(node_buffer_t) + offsetof(node_buffer_elem_t, buf) + NODE_BUF_DEFAULT_LEN * sizeof(NODE)); nb->idx = 0; - nb->len = 16; + nb->len = NODE_BUF_DEFAULT_LEN; nb->head = nb->last = (node_buffer_elem_t*) &nb[1]; nb->head->next = NULL; nb->mark_ary = rb_ary_tmp_new(0); @@ -1193,6 +1195,23 @@ rb_ast_free(rb_ast_t *ast) } } +size_t +rb_ast_memsize(const rb_ast_t *ast) +{ + size_t size = 0; + node_buffer_t *nb = ast->node_buffer; + + if (nb) { + size += sizeof(node_buffer_t) + offsetof(node_buffer_elem_t, buf) + NODE_BUF_DEFAULT_LEN * sizeof(NODE); + node_buffer_elem_t *nbe = nb->head; + while (nbe != nb->last) { + nbe = nbe->next; + size += offsetof(node_buffer_elem_t, buf) + nb->len * sizeof(NODE); + } + } + return size; +} + void rb_ast_dispose(rb_ast_t *ast) { |