Skip to content

Commit e6639f0

Browse files
committed
Refactor ToHexStringNode so it can be DSL inlinable
1 parent 628fa3a commit e6639f0

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,28 +1826,26 @@ protected boolean isUntrusted(Object object,
18261826

18271827
}
18281828

1829-
@GenerateUncached
1830-
@GenerateNodeFactory
18311829
@NodeChild(value = "valueNode", type = RubyNode.class)
18321830
@Primitive(name = "kernel_to_hex")
1833-
public abstract static class ToHexStringNode extends RubySourceNode {
1831+
public abstract static class KernelToHexStringNode extends PrimitiveNode {
18341832

1835-
@NeverDefault
1836-
public static ToHexStringNode create() {
1837-
return KernelNodesFactory.ToHexStringNodeFactory.create(null);
1833+
@Specialization
1834+
protected String toHexString(Object value,
1835+
@Cached ToHexStringNode toHexStringNode) {
1836+
return toHexStringNode.execute(value);
18381837
}
1838+
}
18391839

1840-
public static ToHexStringNode create(RubyNode valueNode) {
1841-
return KernelNodesFactory.ToHexStringNodeFactory.create(valueNode);
1842-
}
1840+
1841+
@GenerateUncached
1842+
public abstract static class ToHexStringNode extends RubyBaseNode {
18431843

18441844
public static ToHexStringNode getUncached() {
1845-
return KernelNodesFactory.ToHexStringNodeFactory.getUncached();
1845+
return KernelNodesFactory.ToHexStringNodeGen.getUncached();
18461846
}
18471847

1848-
public abstract String executeToHexString(Object value);
1849-
1850-
abstract RubyNode getValueNode();
1848+
public abstract String execute(Object value);
18511849

18521850
@Specialization
18531851
protected String toHexString(int value) {
@@ -1864,12 +1862,6 @@ protected String toHexString(long value) {
18641862
protected String toHexString(RubyBignum value) {
18651863
return BigIntegerOps.toString(value.value, 16);
18661864
}
1867-
1868-
@Override
1869-
public RubyNode cloneUninitialized() {
1870-
return create(getValueNode().cloneUninitialized()).copyFlags(this);
1871-
}
1872-
18731865
}
18741866

18751867
@GenerateUncached
@@ -1899,7 +1891,7 @@ protected RubyString toS(Object self,
18991891
@Cached ToHexStringNode toHexStringNode) {
19001892
String className = classNode.execute(self).fields.getName();
19011893
Object id = objectIDNode.execute(self);
1902-
String hexID = toHexStringNode.executeToHexString(id);
1894+
String hexID = toHexStringNode.execute(id);
19031895

19041896
String javaString = Utils.concat("#<", className, ":0x", hexID, ">");
19051897

@@ -1913,7 +1905,7 @@ protected RubyString toS(Object self,
19131905
public static String uncachedBasicToS(Object self) {
19141906
String className = LogicalClassNode.getUncached().execute(self).fields.getName();
19151907
Object id = ObjectIDNode.getUncached().execute(self);
1916-
String hexID = ToHexStringNode.getUncached().executeToHexString(id);
1908+
String hexID = ToHexStringNode.getUncached().execute(id);
19171909

19181910
return "#<" + className + ":0x" + hexID + ">";
19191911
}

0 commit comments

Comments
 (0)