diff options
author | Nobuyoshi Nakada <[email protected]> | 2023-09-01 13:39:36 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2023-09-01 13:39:36 +0900 |
commit | 1fbc8cdf0686657c12cc9014cb4714730adc2ec6 (patch) | |
tree | 6069640e5cdc43513db0a2c2506c148efd025a87 /iseq.c | |
parent | 61f1657f68b9cddf8956380e53b8e7053eeb30c8 (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.c | 25 |
1 files changed, 8 insertions, 17 deletions
@@ -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); |