Skip to content

Commit b80c27a

Browse files
committed
[Truffle] Reuse ReferenceEqualNode for the vm_object_equal primitive.
1 parent 2c4bff3 commit b80c27a

File tree

1 file changed

+10
-57
lines changed

1 file changed

+10
-57
lines changed

truffle/src/main/java/org/jruby/truffle/nodes/rubinius/VMPrimitiveNodes.java

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@
4242
import com.oracle.truffle.api.dsl.Specialization;
4343
import com.oracle.truffle.api.frame.VirtualFrame;
4444
import com.oracle.truffle.api.source.SourceSection;
45+
4546
import jnr.constants.platform.Sysconf;
4647
import jnr.posix.Passwd;
4748
import jnr.posix.Times;
49+
4850
import org.jruby.truffle.nodes.RubyGuards;
4951
import org.jruby.truffle.nodes.RubyNode;
5052
import org.jruby.truffle.nodes.core.*;
53+
import org.jruby.truffle.nodes.core.BasicObjectNodes.ReferenceEqualNode;
54+
import org.jruby.truffle.nodes.core.BasicObjectNodesFactory.ReferenceEqualNodeFactory;
5155
import org.jruby.truffle.nodes.core.array.ArrayNodes;
5256
import org.jruby.truffle.nodes.defined.DefinedWrapperNode;
5357
import org.jruby.truffle.nodes.literal.LiteralNode;
@@ -63,6 +67,7 @@
6367
import org.jruby.truffle.runtime.signal.SignalOperations;
6468
import org.jruby.truffle.runtime.subsystems.ThreadManager;
6569
import org.jruby.util.io.PosixShim;
70+
6671
import sun.misc.Signal;
6772

6873
import java.lang.management.ManagementFactory;
@@ -207,68 +212,16 @@ public RubyClass vmObjectClass(VirtualFrame frame, Object object) {
207212
@RubiniusPrimitive(name = "vm_object_equal", needsSelf = false)
208213
public static abstract class VMObjectEqualPrimitiveNode extends RubiniusPrimitiveNode {
209214

215+
@Child ReferenceEqualNode referenceEqualNode;
216+
210217
public VMObjectEqualPrimitiveNode(RubyContext context, SourceSection sourceSection) {
211218
super(context, sourceSection);
219+
referenceEqualNode = ReferenceEqualNodeFactory.create(context, sourceSection, null, null);
212220
}
213221

214222
@Specialization
215-
public boolean vmObjectEqual(boolean a, boolean b) {
216-
return a == b;
217-
}
218-
219-
@Specialization(guards = "!isBoolean(b)")
220-
public boolean vmObjectEqual(boolean a, Object b) {
221-
return false;
222-
}
223-
224-
@Specialization
225-
public boolean vmObjectEqual(int a, int b) {
226-
return a == b;
227-
}
228-
229-
@Specialization
230-
public boolean vmObjectEqual(int a, long b) {
231-
return a == b;
232-
}
233-
234-
@Specialization(guards = { "!isInteger(b)", "!isLong(b)" })
235-
public boolean vmObjectEqual(int a, Object b) {
236-
return false;
237-
}
238-
239-
@Specialization
240-
public boolean vmObjectEqual(long a, int b) {
241-
return a == b;
242-
}
243-
244-
@Specialization
245-
public boolean vmObjectEqual(long a, long b) {
246-
return a == b;
247-
}
248-
249-
@Specialization(guards = { "!isInteger(b)", "!isLong(b)" })
250-
public boolean vmObjectEqual(long a, Object b) {
251-
return false;
252-
}
253-
254-
@Specialization
255-
public boolean vmObjectEqual(double a, double b) {
256-
return a == b;
257-
}
258-
259-
@Specialization(guards = "!isDouble(b)")
260-
public boolean vmObjectEqual(double a, Object b) {
261-
return false;
262-
}
263-
264-
@Specialization
265-
public boolean vmObjectEqual(RubyBasicObject a, RubyBasicObject b) {
266-
return a == b;
267-
}
268-
269-
@Specialization(guards = "!isRubyBasicObject(b)")
270-
public boolean vmObjectEqual(RubyBasicObject a, Object b) {
271-
return false;
223+
public boolean vmObjectEqual(VirtualFrame frame, Object a, Object b) {
224+
return referenceEqualNode.executeReferenceEqual(frame, a, b);
272225
}
273226

274227
}

0 commit comments

Comments
 (0)