mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
node.h: Reduce struct size to fit with Ruby object size (five VALUEs)
by merging `rb_ast_body_t#line_count` and `#script_lines`. Fortunately `line_count == RARRAY_LEN(script_lines)` was always satisfied. When script_lines is saved, it has an array of lines, and when not saved, it has a Fixnum that represents the old line_count.
This commit is contained in:
parent
acae5f363d
commit
fb01411ae8
Notes:
git
2021-06-18 02:34:57 +09:00
6 changed files with 19 additions and 8 deletions
2
ast.c
2
ast.c
|
@ -710,7 +710,7 @@ ast_node_script_lines(rb_execution_context_t *ec, VALUE self)
|
||||||
struct ASTNodeData *data;
|
struct ASTNodeData *data;
|
||||||
TypedData_Get_Struct(self, struct ASTNodeData, &rb_node_type, data);
|
TypedData_Get_Struct(self, struct ASTNodeData, &rb_node_type, data);
|
||||||
VALUE ret = data->ast->body.script_lines;
|
VALUE ret = data->ast->body.script_lines;
|
||||||
if (!ret) ret = Qnil;
|
if (!RB_TYPE_P(ret, T_ARRAY)) return Qnil;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1328,8 +1328,7 @@ new_child_iseq(rb_iseq_t *iseq, const NODE *const node,
|
||||||
|
|
||||||
ast.root = node;
|
ast.root = node;
|
||||||
ast.compile_option = 0;
|
ast.compile_option = 0;
|
||||||
ast.line_count = -1;
|
ast.script_lines = INT2FIX(-1);
|
||||||
ast.script_lines = Qfalse;
|
|
||||||
|
|
||||||
debugs("[new_child_iseq]> ---------------------------------------\n");
|
debugs("[new_child_iseq]> ---------------------------------------\n");
|
||||||
int isolated_depth = ISEQ_COMPILE_DATA(iseq)->isolated_depth;
|
int isolated_depth = ISEQ_COMPILE_DATA(iseq)->isolated_depth;
|
||||||
|
|
14
iseq.c
14
iseq.c
|
@ -813,13 +813,23 @@ rb_iseq_new(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath,
|
||||||
0, type, &COMPILE_OPTION_DEFAULT);
|
0, type, &COMPILE_OPTION_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
ast_line_count(const rb_ast_body_t *ast)
|
||||||
|
{
|
||||||
|
if (RB_TYPE_P(ast->script_lines, T_ARRAY)){
|
||||||
|
return (int)RARRAY_LEN(ast->script_lines);
|
||||||
|
}
|
||||||
|
return FIX2INT(ast->script_lines);
|
||||||
|
}
|
||||||
|
|
||||||
rb_iseq_t *
|
rb_iseq_t *
|
||||||
rb_iseq_new_top(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent)
|
rb_iseq_new_top(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent)
|
||||||
{
|
{
|
||||||
VALUE coverages = rb_get_coverages();
|
VALUE coverages = rb_get_coverages();
|
||||||
if (RTEST(coverages)) {
|
if (RTEST(coverages)) {
|
||||||
if (ast->line_count >= 0) {
|
int line_count = ast_line_count(ast);
|
||||||
int len = (rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES) ? 0 : ast->line_count;
|
if (line_count >= 0) {
|
||||||
|
int len = (rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES) ? 0 : line_count;
|
||||||
VALUE coverage = rb_default_coverage(len);
|
VALUE coverage = rb_default_coverage(len);
|
||||||
rb_hash_aset(coverages, path, coverage);
|
rb_hash_aset(coverages, path, coverage);
|
||||||
}
|
}
|
||||||
|
|
4
node.h
4
node.h
|
@ -398,8 +398,10 @@ typedef struct node_buffer_struct node_buffer_t;
|
||||||
typedef struct rb_ast_body_struct {
|
typedef struct rb_ast_body_struct {
|
||||||
const NODE *root;
|
const NODE *root;
|
||||||
VALUE compile_option;
|
VALUE compile_option;
|
||||||
int line_count;
|
|
||||||
VALUE script_lines;
|
VALUE script_lines;
|
||||||
|
// script_lines is either:
|
||||||
|
// - a Fixnum that represents the line count of the original source, or
|
||||||
|
// - an Array that contains the lines of the original source
|
||||||
} rb_ast_body_t;
|
} rb_ast_body_t;
|
||||||
typedef struct rb_ast_struct {
|
typedef struct rb_ast_struct {
|
||||||
VALUE flags;
|
VALUE flags;
|
||||||
|
|
2
parse.y
2
parse.y
|
@ -6286,7 +6286,7 @@ yycompile0(VALUE arg)
|
||||||
RB_OBJ_WRITE(p->ast, &p->ast->body.compile_option, opt);
|
RB_OBJ_WRITE(p->ast, &p->ast->body.compile_option, opt);
|
||||||
}
|
}
|
||||||
p->ast->body.root = tree;
|
p->ast->body.root = tree;
|
||||||
p->ast->body.line_count = p->line_count;
|
if (!p->ast->body.script_lines) p->ast->body.script_lines = INT2FIX(p->line_count);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
vm.c
2
vm.c
|
@ -1223,7 +1223,7 @@ rb_binding_add_dynavars(VALUE bindval, rb_binding_t *bind, int dyncount, const I
|
||||||
rb_node_init(&tmp_node, NODE_SCOPE, (VALUE)dyns, 0, 0);
|
rb_node_init(&tmp_node, NODE_SCOPE, (VALUE)dyns, 0, 0);
|
||||||
ast.root = &tmp_node;
|
ast.root = &tmp_node;
|
||||||
ast.compile_option = 0;
|
ast.compile_option = 0;
|
||||||
ast.line_count = -1;
|
ast.script_lines = INT2FIX(-1);
|
||||||
|
|
||||||
if (base_iseq) {
|
if (base_iseq) {
|
||||||
iseq = rb_iseq_new(&ast, base_iseq->body->location.label, path, realpath, base_iseq, ISEQ_TYPE_EVAL);
|
iseq = rb_iseq_new(&ast, base_iseq->body->location.label, path, realpath, base_iseq, ISEQ_TYPE_EVAL);
|
||||||
|
|
Loading…
Reference in a new issue