Skip to content

Commit 6e6ce74

Browse files
committed
Frozen string literals core files no exception dups (GR-12998).
PullRequest: truffleruby/498
2 parents c877bb4 + 13eaf68 commit 6e6ce74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+274
-102
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Changes:
2828
Performance:
2929

3030
* Sped up accesses to native memory through FFI::Pointer.
31+
* All core files now make use of frozen `String` literals, reducing the number
32+
of `String` allocations for core methods.
3133

3234
# 1.0 RC 10
3335

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,13 +2880,10 @@ public RubyNode visitStrNode(StrParseNode node) {
28802880
final Rope rope = context.getRopeCache().getRope(node.getValue(), node.getCodeRange());
28812881
final RubyNode ret;
28822882

2883-
// isFrozen() is set with the magic frozen_string_literal comment or the command line flag.
2884-
// For the command line flag, we do not want to apply it to the core library files.
2885-
// TODO (eregon, 28 Feb 2018): we should respect the magic comment in core (although not used currently).
2886-
if (node.isFrozen() && !inCore()) {
2883+
if (node.isFrozen()) {
28872884
final DynamicObject frozenString = context.getFrozenStringLiteral(rope);
28882885

2889-
ret = new DefinedWrapperNode(context.getCoreStrings().METHOD,
2886+
ret = new DefinedWrapperNode(context.getCoreStrings().EXPRESSION,
28902887
new ObjectLiteralNode(frozenString));
28912888
} else {
28922889
ret = new StringLiteralNode(rope);

src/main/ruby/core/argf.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Copyright (c) 2016, 2017 Oracle and/or its affiliates. All rights reserved. This
1+
# frozen_string_literal: true
2+
3+
# Copyright (c) 2016, 2018 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:
46
#
@@ -568,7 +570,7 @@ def to_io
568570
# Returns "ARGF" as the string representation of this object.
569571
#
570572
def to_s
571-
'ARGF'
573+
+'ARGF'
572574
end
573575

574576

@@ -592,7 +594,7 @@ def advance!
592594
if @argv.empty?
593595
@advance = false
594596
@stream = $stdin
595-
@filename = '-'
597+
@filename = +'-'
596598
@use_stdin_only = true
597599
return true
598600
end

src/main/ruby/core/array.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Copyright (c) 2015, 2017 Oracle and/or its affiliates. All rights reserved. This
1+
# frozen_string_literal: true
2+
3+
# Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:
46
#
@@ -604,11 +606,11 @@ def insert(idx, *items)
604606
Truffle::Graal.always_split instance_method(:insert)
605607

606608
def inspect
607-
return '[]'.force_encoding(Encoding::US_ASCII) if size == 0
609+
return '[]'.encode(Encoding::US_ASCII) if size == 0
608610
comma = ', '
609-
result = '['
611+
result = +'['
610612

611-
return '[...]' if Thread.detect_recursion self do
613+
return +'[...]' if Thread.detect_recursion self do
612614
each_with_index do |element, index|
613615
temp = Truffle::Type.rb_inspect(element)
614616
result.force_encoding(temp.encoding) if index == 0
@@ -624,9 +626,9 @@ def inspect
624626
alias_method :to_s, :inspect
625627

626628
def join(sep=nil)
627-
return ''.force_encoding(Encoding::US_ASCII) if size == 0
629+
return ''.encode(Encoding::US_ASCII) if size == 0
628630

629-
out = ''
631+
out = +''
630632
raise ArgumentError, 'recursive array join' if Thread.detect_recursion self do
631633
sep = sep.nil? ? $, : StringValue(sep)
632634

src/main/ruby/core/basic_object.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2007-2015, Evan Phoenix and contributors
24
# All rights reserved.
35
#

src/main/ruby/core/binding.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2014, 2017 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:

src/main/ruby/core/channel.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2015, 2017 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:

src/main/ruby/core/class.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2007-2015, Evan Phoenix and contributors
24
# All rights reserved.
35
#

src/main/ruby/core/comparable.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2007-2015, Evan Phoenix and contributors
24
# All rights reserved.
35
#

src/main/ruby/core/complex.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2007-2015, Evan Phoenix and contributors
24
# All rights reserved.
35
#

0 commit comments

Comments
 (0)