From 09fa773e04f183e5eb685f07e174efa2cf77f9dc Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Tue, 26 Oct 2021 01:58:01 +0900 Subject: ast.c: Use kept script_lines data instead of re-opening the source file (#5019) ast.c: Use kept script_lines data instead of re-open the source file --- ast.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'ast.c') diff --git a/ast.c b/ast.c index 84e5fdcecc..96116d43eb 100644 --- a/ast.c +++ b/ast.c @@ -195,12 +195,12 @@ script_lines(VALUE path) static VALUE ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE keep_script_lines) { - VALUE path, node, lines; + VALUE path, node, lines = Qnil; int node_id; if (rb_frame_info_p(body)) { - rb_frame_info_get(body, &path, &node_id); - if (NIL_P(path)) return Qnil; + rb_frame_info_get(body, &path, &lines, &node_id); + if (NIL_P(path) && NIL_P(lines)) return Qnil; } else { const rb_iseq_t *iseq = NULL; @@ -220,10 +220,11 @@ ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE keep_script rb_raise(rb_eArgError, "cannot get AST for method defined in eval"); } path = rb_iseq_path(iseq); + lines = iseq->body->variable.script_lines; node_id = iseq->body->location.node_id; } - if (!NIL_P(lines = script_lines(path))) { + if (!NIL_P(lines) || !NIL_P(lines = script_lines(path))) { node = rb_ast_parse_array(lines, keep_script_lines); } else if (RSTRING_LEN(path) == 2 && memcmp(RSTRING_PTR(path), "-e", 2) == 0) { -- cgit v1.2.3