Skip to content

Commit 71bdae0

Browse files
committed
[Truffle] Used ToStrNode in a place that used to use CallDispatchHeadNode.
1 parent 21a7cdb commit 71bdae0

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.joni.Region;
2424
import org.jruby.runtime.Visibility;
2525
import org.jruby.truffle.nodes.RubyNode;
26+
import org.jruby.truffle.nodes.coerce.ToStrNode;
27+
import org.jruby.truffle.nodes.coerce.ToStrNodeFactory;
2628
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
2729
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
2830
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
@@ -552,11 +554,11 @@ public RubyString chompBangWithString(RubyString string, RubyString stringToChom
552554
@CoreMethod(names = "count", argumentsAsArray = true)
553555
public abstract static class CountNode extends CoreMethodNode {
554556

555-
@Child private CallDispatchHeadNode toStr;
557+
@Child private ToStrNode toStr;
556558

557559
public CountNode(RubyContext context, SourceSection sourceSection) {
558560
super(context, sourceSection);
559-
toStr = DispatchHeadNodeFactory.createMethodCall(context);
561+
toStr = ToStrNodeFactory.create(context, sourceSection, null);
560562
}
561563

562564
public CountNode(CountNode prev) {
@@ -580,30 +582,7 @@ private int countSlow(VirtualFrame frame, RubyString string, Object[] args) {
580582
RubyString[] otherStrings = new RubyString[args.length];
581583

582584
for (int i = 0; i < args.length; i++) {
583-
if (args[i] instanceof RubyString) {
584-
otherStrings[i] = (RubyString) args[i];
585-
} else {
586-
Object coerced;
587-
588-
try {
589-
coerced = toStr.call(frame, args[i], "to_str", null);
590-
} catch (RaiseException e) {
591-
if (e.getRubyException().getLogicalClass() == getContext().getCoreLibrary().getNoMethodErrorClass()) {
592-
throw new RaiseException(
593-
getContext().getCoreLibrary().typeErrorNoImplicitConversion(args[i], "String", this));
594-
} else {
595-
throw e;
596-
}
597-
}
598-
599-
if (coerced instanceof RubyString) {
600-
otherStrings[i] = (RubyString) coerced;
601-
} else {
602-
throw new RaiseException(
603-
getContext().getCoreLibrary().typeErrorBadCoercion(args[i], "String", "to_str", coerced, this));
604-
605-
}
606-
}
585+
otherStrings[i] = toStr.executeRubyString(frame, args[i]);
607586
}
608587

609588
return string.count(otherStrings);

0 commit comments

Comments
 (0)