From fb01411ae842dbcc16d18dec2216fa2719649dff Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Fri, 18 Jun 2021 01:31:50 +0900 Subject: 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. --- iseq.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'iseq.c') diff --git a/iseq.c b/iseq.c index 4ad1fc23be..1609432770 100644 --- a/iseq.c +++ b/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); } +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_new_top(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent) { VALUE coverages = rb_get_coverages(); if (RTEST(coverages)) { - if (ast->line_count >= 0) { - int len = (rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES) ? 0 : ast->line_count; + int line_count = ast_line_count(ast); + if (line_count >= 0) { + int len = (rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES) ? 0 : line_count; VALUE coverage = rb_default_coverage(len); rb_hash_aset(coverages, path, coverage); } -- cgit v1.2.3