Skip to content

Commit 4420a30

Browse files
committed
[GR-38034] Replace a call of -"string" with frozen string literal at parse time
PullRequest: truffleruby/3395
2 parents 9d34b00 + 7b85e23 commit 4420a30

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Compatibility:
1313

1414
Performance:
1515

16+
* Replace a call of `-"string"` with frozen string literal at parse time (@andrykonchin).
1617

1718
Changes:
1819

src/main/java/org/truffleruby/parser/BodyTranslator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ public RubyNode visitCallNode(CallParseNode node) {
509509
final ParseNode receiver = node.getReceiverNode();
510510
final String methodName = node.getName();
511511

512-
if (receiver instanceof StrParseNode && methodName.equals("freeze")) {
512+
if (receiver instanceof StrParseNode &&
513+
(methodName.equals("freeze") || methodName.equals("-@"))) {
513514
final StrParseNode strNode = (StrParseNode) receiver;
514515
final Rope nodeRope = strNode.getValue();
515516
final ImmutableRubyString frozenString = language

test/mri/excludes/TestRubyOptimization.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
exclude :test_hash_aref_with, "needs investigation"
44
exclude :test_nil_safe_conditional_assign, "needs investigation"
55
exclude :test_optimized_rescue, "needs investigation"
6-
exclude :test_string_freeze, "needs investigation"
6+
exclude :test_string_freeze, "TruffleRuby does not consider redefined String#freeze on string literals for simplicity"
7+
exclude :test_string_uminus, "TruffleRuby does not consider redefined String#-@ on string literals for simplicity"
78
exclude :test_string_freeze_block, "needs investigation"
89
exclude :test_string_freeze_saves_memory, "needs investigation"
910
exclude :test_string_length, "needs investigation"

0 commit comments

Comments
 (0)