summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-09-01 13:39:36 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-09-01 13:39:36 +0900
commit1fbc8cdf0686657c12cc9014cb4714730adc2ec6 (patch)
tree6069640e5cdc43513db0a2c2506c148efd025a87 /iseq.c
parent61f1657f68b9cddf8956380e53b8e7053eeb30c8 (diff)
Copy `rb_compile_option_t` only if needed
Use `COMPILE_OPTION_DEFAULT` if nothing to change.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/8349
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/iseq.c b/iseq.c
index 7d64177e99..3b91317d33 100644
--- a/iseq.c
+++ b/iseq.c
@@ -916,13 +916,12 @@ rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE rea
rb_iseq_t *iseq = iseq_alloc();
rb_compile_option_t new_opt;
- if (option) {
+ if (!option) option = &COMPILE_OPTION_DEFAULT;
+ if (ast) {
new_opt = *option;
+ rb_iseq_make_compile_option(&new_opt, make_compile_option_from_ast(ast));
+ option = &new_opt;
}
- else {
- new_opt = COMPILE_OPTION_DEFAULT;
- }
- if (ast) rb_iseq_make_compile_option(&new_opt, make_compile_option_from_ast(ast));
VALUE script_lines = Qnil;
@@ -934,7 +933,7 @@ rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE rea
}
prepare_iseq_build(iseq, name, path, realpath, first_lineno, node ? &node->nd_loc : NULL, node ? nd_node_id(node) : -1,
- parent, isolated_depth, type, script_lines, &new_opt);
+ parent, isolated_depth, type, script_lines, option);
rb_iseq_compile_node(iseq, node);
finish_iseq_build(iseq);
@@ -950,19 +949,11 @@ yp_iseq_new_with_opt(yp_node_t *node, yp_parser_t *parser, VALUE name, VALUE pat
enum rb_iseq_type type, const rb_compile_option_t *option)
{
rb_iseq_t *iseq = iseq_alloc();
- rb_compile_option_t new_opt;
-
- if (option) {
- new_opt = *option;
- }
- else {
- new_opt = COMPILE_OPTION_DEFAULT;
- }
-
VALUE script_lines = Qnil;
-
rb_code_location_t code_loc;
+ if (!option) option = &COMPILE_OPTION_DEFAULT;
+
if (node) {
yp_line_column_t start_line_col = yp_newline_list_line_column(&(parser->newline_list), node->location.start);
yp_line_column_t end_line_col= yp_newline_list_line_column(&(parser->newline_list), node->location.end);
@@ -981,7 +972,7 @@ yp_iseq_new_with_opt(yp_node_t *node, yp_parser_t *parser, VALUE name, VALUE pat
// TODO: node_id
int node_id = -1;
prepare_iseq_build(iseq, name, path, realpath, first_lineno, &code_loc, node_id,
- parent, isolated_depth, type, script_lines, &new_opt);
+ parent, isolated_depth, type, script_lines, option);
rb_iseq_compile_yarp_node(iseq, node, parser);