Skip to content

Commit

Permalink
[Truffle] Used ToStrNode in a place that used to use CallDispatchHead…
Browse files Browse the repository at this point in the history
…Node.
  • Loading branch information
nirvdrum committed Feb 6, 2015
1 parent 21a7cdb commit 71bdae0
Showing 1 changed file with 5 additions and 26 deletions.
Expand Up @@ -23,6 +23,8 @@
import org.joni.Region;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.coerce.ToStrNode;
import org.jruby.truffle.nodes.coerce.ToStrNodeFactory;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
Expand Down Expand Up @@ -552,11 +554,11 @@ public RubyString chompBangWithString(RubyString string, RubyString stringToChom
@CoreMethod(names = "count", argumentsAsArray = true)
public abstract static class CountNode extends CoreMethodNode {

@Child private CallDispatchHeadNode toStr;
@Child private ToStrNode toStr;

public CountNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
toStr = DispatchHeadNodeFactory.createMethodCall(context);
toStr = ToStrNodeFactory.create(context, sourceSection, null);
}

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

for (int i = 0; i < args.length; i++) {
if (args[i] instanceof RubyString) {
otherStrings[i] = (RubyString) args[i];
} else {
Object coerced;

try {
coerced = toStr.call(frame, args[i], "to_str", null);
} catch (RaiseException e) {
if (e.getRubyException().getLogicalClass() == getContext().getCoreLibrary().getNoMethodErrorClass()) {
throw new RaiseException(
getContext().getCoreLibrary().typeErrorNoImplicitConversion(args[i], "String", this));
} else {
throw e;
}
}

if (coerced instanceof RubyString) {
otherStrings[i] = (RubyString) coerced;
} else {
throw new RaiseException(
getContext().getCoreLibrary().typeErrorBadCoercion(args[i], "String", "to_str", coerced, this));

}
}
otherStrings[i] = toStr.executeRubyString(frame, args[i]);
}

return string.count(otherStrings);
Expand Down

0 comments on commit 71bdae0

Please sign in to comment.