summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKazuki Tsujimoto <kazuki@callcc.net>2020-08-02 01:03:43 +0900
committerKazuki Tsujimoto <kazuki@callcc.net>2020-08-02 01:04:06 +0900
commitfcdbdff631a1a6bcc2229d448ed7c76041fe3258 (patch)
treecb73eb7446f547b744365e9141657f4790ab92b2
parentb6175c9e4fe25b978252d8998fe791d65d998fc5 (diff)
downloadruby-fcdbdff631a1a6bcc2229d448ed7c76041fe3258.tar.gz
rb_{ary,fnd}_pattern_info: Remove imemo member to reduce memory usage
This is a partial revert commit of 8f096226e1b76f95f4d853d3dea2bc75eeeb5244. NODE layout: Before: | ARYPTN | FNDPTN | HSHPTN ---+--------+--------+----------- u1 | pconst | pconst | pconst u2 | unused | unused | pkwargs u3 | apinfo | fpinfo | pkwrestarg After: | ARYPTN | FNDPTN | HSHPTN ---+--------+--------+----------- u1 | imemo | imemo | pkwargs u2 | pconst | pconst | pconst u3 | apinfo | fpinfo | pkwrestarg
-rw-r--r--node.c28
-rw-r--r--node.h6
-rw-r--r--parse.y48
3 files changed, 19 insertions, 63 deletions
diff --git a/node.c b/node.c
index 01ec4bee04..7c291a80ad 100644
--- a/node.c
+++ b/node.c
@@ -1294,18 +1294,6 @@ static void
mark_ast_value(void *ctx, NODE * node)
{
switch (nd_type(node)) {
- case NODE_ARYPTN:
- {
- struct rb_ary_pattern_info *apinfo = node->nd_apinfo;
- rb_gc_mark_movable(apinfo->imemo);
- break;
- }
- case NODE_FNDPTN:
- {
- struct rb_fnd_pattern_info *fpinfo = node->nd_fpinfo;
- rb_gc_mark_movable(fpinfo->imemo);
- break;
- }
case NODE_ARGS:
{
struct rb_args_info *args = node->nd_ainfo;
@@ -1320,6 +1308,8 @@ mark_ast_value(void *ctx, NODE * node)
case NODE_DXSTR:
case NODE_DREGX:
case NODE_DSYM:
+ case NODE_ARYPTN:
+ case NODE_FNDPTN:
rb_gc_mark_movable(node->nd_lit);
break;
default:
@@ -1331,18 +1321,6 @@ static void
update_ast_value(void *ctx, NODE * node)
{
switch (nd_type(node)) {
- case NODE_ARYPTN:
- {
- struct rb_ary_pattern_info *apinfo = node->nd_apinfo;
- apinfo->imemo = rb_gc_location(apinfo->imemo);
- break;
- }
- case NODE_FNDPTN:
- {
- struct rb_fnd_pattern_info *fpinfo = node->nd_fpinfo;
- fpinfo->imemo = rb_gc_location(fpinfo->imemo);
- break;
- }
case NODE_ARGS:
{
struct rb_args_info *args = node->nd_ainfo;
@@ -1357,6 +1335,8 @@ update_ast_value(void *ctx, NODE * node)
case NODE_DXSTR:
case NODE_DREGX:
case NODE_DSYM:
+ case NODE_ARYPTN:
+ case NODE_FNDPTN:
node->nd_lit = rb_gc_location(node->nd_lit);
break;
default:
diff --git a/node.h b/node.h
index 8252955ef2..b6fefb4410 100644
--- a/node.h
+++ b/node.h
@@ -273,8 +273,8 @@ typedef struct RNode {
#define nd_brace u2.argc
-#define nd_pconst u1.node
-#define nd_pkwargs u2.node
+#define nd_pkwargs u1.node
+#define nd_pconst u2.node
#define nd_pkwrestarg u3.node
#define nd_apinfo u3.apinfo
@@ -458,14 +458,12 @@ struct rb_ary_pattern_info {
NODE *pre_args;
NODE *rest_arg;
NODE *post_args;
- VALUE imemo;
};
struct rb_fnd_pattern_info {
NODE *pre_rest_arg;
NODE *args;
NODE *post_rest_arg;
- VALUE imemo;
};
struct parser_params;
diff --git a/parse.y b/parse.y
index b29e7190eb..ba10c55199 100644
--- a/parse.y
+++ b/parse.y
@@ -829,12 +829,7 @@ static VALUE
new_array_pattern(struct parser_params *p, VALUE constant, VALUE pre_arg, VALUE aryptn, const YYLTYPE *loc)
{
NODE *t = (NODE *)aryptn;
- struct rb_ary_pattern_info *apinfo = t->nd_apinfo;
- VALUE pre_args, rest_arg, post_args;
-
- pre_args = rb_ary_entry(apinfo->imemo, 0);
- rest_arg = rb_ary_entry(apinfo->imemo, 1);
- post_args = rb_ary_entry(apinfo->imemo, 2);
+ VALUE pre_args = t->u1.value, rest_arg = t->u2.value, post_args = t->u3.value;
if (!NIL_P(pre_arg)) {
if (!NIL_P(pre_args)) {
@@ -851,7 +846,6 @@ static VALUE
new_array_pattern_tail(struct parser_params *p, VALUE pre_args, VALUE has_rest, VALUE rest_arg, VALUE post_args, const YYLTYPE *loc)
{
NODE *t;
- struct rb_ary_pattern_info *apinfo;
if (has_rest) {
rest_arg = dispatch1(var_field, rest_arg ? rest_arg : Qnil);
@@ -860,14 +854,10 @@ new_array_pattern_tail(struct parser_params *p, VALUE pre_args, VALUE has_rest,
rest_arg = Qnil;
}
- VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer();
- apinfo = ZALLOC(struct rb_ary_pattern_info);
- rb_imemo_tmpbuf_set_ptr(tmpbuf, apinfo);
- apinfo->imemo = rb_ary_new_from_args(4, pre_args, rest_arg, post_args, tmpbuf);
-
- t = rb_node_newnode(NODE_ARYPTN, Qnil, Qnil, (VALUE)apinfo, &NULL_LOC);
- RB_OBJ_WRITTEN(p->ast, Qnil, apinfo->imemo);
-
+ t = rb_node_newnode(NODE_ARYPTN, pre_args, rest_arg, post_args, &NULL_LOC);
+ add_mark_object(p, pre_args);
+ add_mark_object(p, rest_arg);
+ add_mark_object(p, post_args);
return (VALUE)t;
}
@@ -875,12 +865,7 @@ static VALUE
new_find_pattern(struct parser_params *p, VALUE constant, VALUE fndptn, const YYLTYPE *loc)
{
NODE *t = (NODE *)fndptn;
- struct rb_fnd_pattern_info *fpinfo = t->nd_fpinfo;
- VALUE pre_rest_arg, args, post_rest_arg;
-
- pre_rest_arg = rb_ary_entry(fpinfo->imemo, 0);
- args = rb_ary_entry(fpinfo->imemo, 1);
- post_rest_arg = rb_ary_entry(fpinfo->imemo, 2);
+ VALUE pre_rest_arg = t->u1.value, args = t->u2.value, post_rest_arg = t->u3.value;
return dispatch4(fndptn, constant, pre_rest_arg, args, post_rest_arg);
}
@@ -889,19 +874,14 @@ static VALUE
new_find_pattern_tail(struct parser_params *p, VALUE pre_rest_arg, VALUE args, VALUE post_rest_arg, const YYLTYPE *loc)
{
NODE *t;
- struct rb_fnd_pattern_info *fpinfo;
pre_rest_arg = dispatch1(var_field, pre_rest_arg ? pre_rest_arg : Qnil);
post_rest_arg = dispatch1(var_field, post_rest_arg ? post_rest_arg : Qnil);
- VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer();
- fpinfo = ZALLOC(struct rb_fnd_pattern_info);
- rb_imemo_tmpbuf_set_ptr(tmpbuf, fpinfo);
- fpinfo->imemo = rb_ary_new_from_args(4, pre_rest_arg, args, post_rest_arg, tmpbuf);
-
- t = rb_node_newnode(NODE_FNDPTN, Qnil, Qnil, (VALUE)fpinfo, &NULL_LOC);
- RB_OBJ_WRITTEN(p->ast, Qnil, fpinfo->imemo);
-
+ t = rb_node_newnode(NODE_FNDPTN, pre_rest_arg, args, post_rest_arg, &NULL_LOC);
+ add_mark_object(p, pre_rest_arg);
+ add_mark_object(p, args);
+ add_mark_object(p, post_rest_arg);
return (VALUE)t;
}
@@ -11602,8 +11582,7 @@ new_array_pattern_tail(struct parser_params *p, NODE *pre_args, int has_rest, ID
VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer();
struct rb_ary_pattern_info *apinfo = ZALLOC(struct rb_ary_pattern_info);
rb_imemo_tmpbuf_set_ptr(tmpbuf, apinfo);
- node = NEW_NODE(NODE_ARYPTN, 0, 0, apinfo, loc);
- apinfo->imemo = tmpbuf;
+ node = NEW_NODE(NODE_ARYPTN, tmpbuf, 0, apinfo, loc);
RB_OBJ_WRITTEN(p->ast, Qnil, tmpbuf);
apinfo->pre_args = pre_args;
@@ -11642,8 +11621,7 @@ new_find_pattern_tail(struct parser_params *p, ID pre_rest_arg, NODE *args, ID p
VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer();
struct rb_fnd_pattern_info *fpinfo = ZALLOC(struct rb_fnd_pattern_info);
rb_imemo_tmpbuf_set_ptr(tmpbuf, fpinfo);
- node = NEW_NODE(NODE_FNDPTN, 0, 0, fpinfo, loc);
- fpinfo->imemo = tmpbuf;
+ node = NEW_NODE(NODE_FNDPTN, tmpbuf, 0, fpinfo, loc);
RB_OBJ_WRITTEN(p->ast, Qnil, tmpbuf);
fpinfo->pre_rest_arg = pre_rest_arg ? assignable(p, pre_rest_arg, 0, loc) : NODE_SPECIAL_NO_NAME_REST;
@@ -11677,7 +11655,7 @@ new_hash_pattern_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, co
kw_rest_arg_node = NULL;
}
- node = NEW_NODE(NODE_HSHPTN, 0, kw_args, kw_rest_arg_node, loc);
+ node = NEW_NODE(NODE_HSHPTN, kw_args, 0, kw_rest_arg_node, loc);
p->ruby_sourceline = saved_line;
return node;