summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2021-11-18 03:40:49 +0900
committerYusuke Endoh <mame@ruby-lang.org>2021-11-21 08:59:24 +0900
commitfeda058531c0bdd5b673180accb4407dcc798c79 (patch)
tree7a9e59021282949f551b690feee031919ddd8a5a /vm.c
parent86ad878e6a0781749c73574112a0fac4f088e2c9 (diff)
Refactor hacky ID tables to struct rb_ast_id_table_t
The implementation of a local variable tables was represented as `ID*`, but it was very hacky: the first element is not an ID but the size of the table, and, the last element is (sometimes) a link to the next local table only when the id tables are a linked list. This change converts the hacky implementation to a normal struct.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5136
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/vm.c b/vm.c
index 5941329c4e..53f16275c3 100644
--- a/vm.c
+++ b/vm.c
@@ -1256,18 +1256,17 @@ rb_binding_add_dynavars(VALUE bindval, rb_binding_t *bind, int dyncount, const I
const rb_iseq_t *base_iseq, *iseq;
rb_ast_body_t ast;
NODE tmp_node;
- ID minibuf[4], *dyns = minibuf;
- VALUE idtmp = 0;
if (dyncount < 0) return 0;
base_block = &bind->block;
base_iseq = vm_block_iseq(base_block);
- if (dyncount >= numberof(minibuf)) dyns = ALLOCV_N(ID, idtmp, dyncount + 1);
+ VALUE idtmp = 0;
+ rb_ast_id_table_t *dyns = ALLOCV(idtmp, sizeof(rb_ast_id_table_t) + dyncount * sizeof(ID));
+ dyns->size = dyncount;
+ MEMCPY(dyns->ids, dynvars, ID, dyncount);
- dyns[0] = dyncount;
- MEMCPY(dyns + 1, dynvars, ID, dyncount);
rb_node_init(&tmp_node, NODE_SCOPE, (VALUE)dyns, 0, 0);
ast.root = &tmp_node;
ast.compile_option = 0;