Skip to content

Commit 11e8c5c

Browse files
committed
CheckIndexNode is DSL inlinable
1 parent 70559ba commit 11e8c5c

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/main/java/org/truffleruby/core/string/StringHelperNodes.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,28 +417,30 @@ protected Object getAssociatedImmutable(ImmutableRubyString string) {
417417

418418
}
419419

420+
@GenerateInline
421+
@GenerateCached(false)
420422
public abstract static class CheckIndexNode extends RubyBaseNode {
421423

422-
public abstract int executeCheck(int index, int length);
424+
public abstract int execute(Node node, int index, int length);
423425

424426
@Specialization
425-
protected int checkIndex(int index, int length,
427+
protected static int checkIndex(Node node, int index, int length,
426428
@Cached InlinedConditionProfile negativeIndexProfile,
427429
@Cached InlinedBranchProfile errorProfile) {
428430
if (index >= length) {
429-
errorProfile.enter(this);
431+
errorProfile.enter(node);
430432
throw new RaiseException(
431-
getContext(),
432-
getContext().getCoreExceptions().indexErrorOutOfString(index, this));
433+
getContext(node),
434+
getContext(node).getCoreExceptions().indexErrorOutOfString(index, node));
433435
}
434436

435-
if (negativeIndexProfile.profile(this, index < 0)) {
437+
if (negativeIndexProfile.profile(node, index < 0)) {
436438
index += length;
437439
if (index < 0) {
438-
errorProfile.enter(this);
440+
errorProfile.enter(node);
439441
throw new RaiseException(
440-
getContext(),
441-
getContext().getCoreExceptions().indexErrorOutOfString(index, this));
442+
getContext(node),
443+
getContext(node).getCoreExceptions().indexErrorOutOfString(index, node));
442444
}
443445
}
444446

src/main/java/org/truffleruby/core/string/StringNodes.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,27 +2268,27 @@ public abstract static class SetByteNode extends RubyBaseNode {
22682268
public abstract int execute(Node node, RubyString string, int index, int value);
22692269

22702270
@Specialization(guards = "tstring.isMutable()")
2271-
protected static int mutable(RubyString string, int index, int value,
2271+
protected static int mutable(Node node, RubyString string, int index, int value,
22722272
@Cached @Shared StringHelperNodes.CheckIndexNode checkIndexNode,
22732273
@Cached @Shared RubyStringLibrary libString,
22742274
@Bind("string.tstring") AbstractTruffleString tstring,
22752275
@Cached @Shared MutableTruffleString.WriteByteNode writeByteNode) {
22762276
var tencoding = libString.getTEncoding(string);
2277-
final int normalizedIndex = checkIndexNode.executeCheck(index, tstring.byteLength(tencoding));
2277+
final int normalizedIndex = checkIndexNode.execute(node, index, tstring.byteLength(tencoding));
22782278

22792279
writeByteNode.execute((MutableTruffleString) tstring, normalizedIndex, (byte) value, tencoding);
22802280
return value;
22812281
}
22822282

22832283
@Specialization(guards = "!tstring.isMutable()")
2284-
protected static int immutable(RubyString string, int index, int value,
2284+
protected static int immutable(Node node, RubyString string, int index, int value,
22852285
@Cached @Shared StringHelperNodes.CheckIndexNode checkIndexNode,
22862286
@Cached @Shared RubyStringLibrary libString,
22872287
@Bind("string.tstring") AbstractTruffleString tstring,
22882288
@Cached MutableTruffleString.AsMutableTruffleStringNode asMutableTruffleStringNode,
22892289
@Cached @Shared MutableTruffleString.WriteByteNode writeByteNode) {
22902290
var tencoding = libString.getTEncoding(string);
2291-
final int normalizedIndex = checkIndexNode.executeCheck(index, tstring.byteLength(tencoding));
2291+
final int normalizedIndex = checkIndexNode.execute(node, index, tstring.byteLength(tencoding));
22922292

22932293
MutableTruffleString mutableTString = asMutableTruffleStringNode.execute(tstring, tencoding);
22942294
writeByteNode.execute(mutableTString, normalizedIndex, (byte) value, tencoding);

0 commit comments

Comments
 (0)