Skip to content

Commit 1eff21e

Browse files
committed
Use helper method for checking if TruffleString is immutable for clarity.
1 parent d16c5b0 commit 1eff21e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/main/java/org/truffleruby/core/encoding/TStringUtils.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ public static TruffleString fromJavaString(String javaString, RubyEncoding encod
7979
public static byte[] getBytesOrCopy(AbstractTruffleString tstring, RubyEncoding encoding) {
8080
CompilerAsserts.neverPartOfCompilation("uncached");
8181
var bytes = tstring.getInternalByteArrayUncached(encoding.tencoding);
82-
if (tstring instanceof TruffleString && bytes.getOffset() == 0 &&
83-
bytes.getLength() == bytes.getArray().length) {
82+
if (tstring.isImmutable() && bytes.getOffset() == 0 && bytes.getLength() == bytes.getArray().length) {
8483
return bytes.getArray();
8584
} else {
8685
return ArrayUtils.extractRange(bytes.getArray(), bytes.getOffset(), bytes.getEnd());
@@ -92,8 +91,8 @@ public static byte[] getBytesOrCopy(Node node, AbstractTruffleString tstring, Tr
9291
TruffleString.GetInternalByteArrayNode getInternalByteArrayNode,
9392
InlinedConditionProfile noCopyProfile) {
9493
var bytes = getInternalByteArrayNode.execute(tstring, encoding);
95-
if (noCopyProfile.profile(node, tstring instanceof TruffleString && bytes.getOffset() == 0 &&
96-
bytes.getLength() == bytes.getArray().length)) {
94+
if (noCopyProfile.profile(node,
95+
tstring.isImmutable() && bytes.getOffset() == 0 && bytes.getLength() == bytes.getArray().length)) {
9796
return bytes.getArray();
9897
} else {
9998
return ArrayUtils.extractRange(bytes.getArray(), bytes.getOffset(), bytes.getEnd());

0 commit comments

Comments
 (0)