Skip to content

Commit 9925333

Browse files
committed
Refactor SetByteNode to get rid of CreateCast
1 parent 049b954 commit 9925333

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,23 +2248,28 @@ protected RubyString undumpNonAsciiCompatible(Object string,
22482248
@NodeChild(value = "index", type = RubyBaseNodeWithExecute.class)
22492249
@NodeChild(value = "value", type = RubyBaseNodeWithExecute.class)
22502250
@ImportStatic(StringGuards.class)
2251-
public abstract static class SetByteNode extends CoreMethodNode {
2251+
public abstract static class StringSetByteNode extends CoreMethodNode {
22522252

2253-
@Child private StringHelperNodes.CheckIndexNode checkIndexNode = StringHelperNodesFactory.CheckIndexNodeGen
2254-
.create();
2255-
2256-
@CreateCast("index")
2257-
protected ToIntNode coerceIndexToInt(RubyBaseNodeWithExecute index) {
2258-
return ToIntNode.create(index);
2253+
@Specialization
2254+
protected int doSetByte(RubyString string, Object indexObject, Object valueObject,
2255+
@Cached ToIntNode toIntIndexNode,
2256+
@Cached ToIntNode toIntValueNode,
2257+
@Cached SetByteNode setByteNode) {
2258+
int index = toIntIndexNode.execute(indexObject);
2259+
int value = toIntValueNode.execute(valueObject);
2260+
return setByteNode.execute(this, string, index, value);
22592261
}
2262+
}
22602263

2261-
@CreateCast("value")
2262-
protected ToIntNode coerceValueToInt(RubyBaseNodeWithExecute value) {
2263-
return ToIntNode.create(value);
2264-
}
2264+
@GenerateInline
2265+
@GenerateCached(false)
2266+
public abstract static class SetByteNode extends RubyBaseNode {
2267+
2268+
public abstract int execute(Node node, RubyString string, int index, int value);
22652269

22662270
@Specialization(guards = "tstring.isMutable()")
2267-
protected int mutable(RubyString string, int index, int value,
2271+
protected static int mutable(RubyString string, int index, int value,
2272+
@Cached @Shared StringHelperNodes.CheckIndexNode checkIndexNode,
22682273
@Cached @Shared RubyStringLibrary libString,
22692274
@Bind("string.tstring") AbstractTruffleString tstring,
22702275
@Cached @Shared MutableTruffleString.WriteByteNode writeByteNode) {
@@ -2276,7 +2281,8 @@ protected int mutable(RubyString string, int index, int value,
22762281
}
22772282

22782283
@Specialization(guards = "!tstring.isMutable()")
2279-
protected int immutable(RubyString string, int index, int value,
2284+
protected static int immutable(RubyString string, int index, int value,
2285+
@Cached @Shared StringHelperNodes.CheckIndexNode checkIndexNode,
22802286
@Cached @Shared RubyStringLibrary libString,
22812287
@Bind("string.tstring") AbstractTruffleString tstring,
22822288
@Cached MutableTruffleString.AsMutableTruffleStringNode asMutableTruffleStringNode,

0 commit comments

Comments
 (0)