diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2024-02-01 15:15:07 -0500 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2024-02-01 15:50:32 -0500 |
commit | b47d43fa9bd48d14f871f71c2dfa18e241f0f051 (patch) | |
tree | 986a7a6396da86479c171b54ecb733188f5250f0 /prism_compile.c | |
parent | c7fe3ecb49784fcc6a9780f89880d758cd272449 (diff) |
[PRISM] Use rb_fstring() on all string literals
In addition to saving space by deduplicating, this also makes the
literals have code range like TestObjSpace#test_dump_string_coderange
expects. It's testing a detail, but we might as well use rb_fstring().
Note that `putstring` makes a mutable duplicate, so passing it an
fstring is fine.
Diffstat (limited to 'prism_compile.c')
-rw-r--r-- | prism_compile.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/prism_compile.c b/prism_compile.c index 58a71fcfdb..a54f2a71a9 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -753,11 +753,12 @@ pm_interpolated_node_compile(pm_node_list_t *parts, rb_iseq_t *iseq, NODE dummy_ } else { if (RTEST(current_string)) { + current_string = rb_fstring(current_string); if (parser->frozen_string_literal) { - ADD_INSN1(ret, &dummy_line_node, putobject, rb_str_freeze(current_string)); + ADD_INSN1(ret, &dummy_line_node, putobject, current_string); } else { - ADD_INSN1(ret, &dummy_line_node, putstring, rb_str_freeze(current_string)); + ADD_INSN1(ret, &dummy_line_node, putstring, current_string); } current_string = Qnil; number_of_items_pushed++; @@ -772,11 +773,12 @@ pm_interpolated_node_compile(pm_node_list_t *parts, rb_iseq_t *iseq, NODE dummy_ } if (RTEST(current_string)) { + current_string = rb_fstring(current_string); if (parser->frozen_string_literal) { - ADD_INSN1(ret, &dummy_line_node, putobject, rb_str_freeze(current_string)); + ADD_INSN1(ret, &dummy_line_node, putobject, current_string); } else { - ADD_INSN1(ret, &dummy_line_node, putstring, rb_str_freeze(current_string)); + ADD_INSN1(ret, &dummy_line_node, putstring, current_string); } current_string = Qnil; number_of_items_pushed++; @@ -7382,8 +7384,9 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, if (!popped) { pm_string_node_t *cast = (pm_string_node_t *) node; VALUE value = parse_string_encoded(node, &cast->unescaped, parser); + value = rb_fstring(value); if (node->flags & PM_STRING_FLAGS_FROZEN) { - ADD_INSN1(ret, &dummy_line_node, putobject, rb_fstring(value)); + ADD_INSN1(ret, &dummy_line_node, putobject, value); } else { ADD_INSN1(ret, &dummy_line_node, putstring, value); |