Skip to content

Commit 7b85e23

Browse files
committed
Replace a call of -"string" with frozen string literal at parse time
1 parent dcd78ca commit 7b85e23

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
@@ -11,6 +11,7 @@ Compatibility:
1111

1212
Performance:
1313

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

1516
Changes:
1617

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)