summaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2021-10-26 01:58:01 +0900
committerGitHub <noreply@github.com>2021-10-26 01:58:01 +0900
commit09fa773e04f183e5eb685f07e174efa2cf77f9dc (patch)
tree43b58901056217443ddfcee79decd2a9c71596cc /ast.c
parent33113c6b64b9017e8b31b6c5e9cbcd7bdf30f05a (diff)
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
Notes
Notes: Merged-By: mame <mame@ruby-lang.org>
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c9
1 files changed, 5 insertions, 4 deletions
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) {