23
23
import org .joni .Region ;
24
24
import org .jruby .runtime .Visibility ;
25
25
import org .jruby .truffle .nodes .RubyNode ;
26
+ import org .jruby .truffle .nodes .coerce .ToStrNode ;
27
+ import org .jruby .truffle .nodes .coerce .ToStrNodeFactory ;
26
28
import org .jruby .truffle .nodes .dispatch .CallDispatchHeadNode ;
27
29
import org .jruby .truffle .nodes .dispatch .DispatchHeadNode ;
28
30
import org .jruby .truffle .nodes .dispatch .DispatchHeadNodeFactory ;
@@ -552,11 +554,11 @@ public RubyString chompBangWithString(RubyString string, RubyString stringToChom
552
554
@ CoreMethod (names = "count" , argumentsAsArray = true )
553
555
public abstract static class CountNode extends CoreMethodNode {
554
556
555
- @ Child private CallDispatchHeadNode toStr ;
557
+ @ Child private ToStrNode toStr ;
556
558
557
559
public CountNode (RubyContext context , SourceSection sourceSection ) {
558
560
super (context , sourceSection );
559
- toStr = DispatchHeadNodeFactory . createMethodCall (context );
561
+ toStr = ToStrNodeFactory . create (context , sourceSection , null );
560
562
}
561
563
562
564
public CountNode (CountNode prev ) {
@@ -580,30 +582,7 @@ private int countSlow(VirtualFrame frame, RubyString string, Object[] args) {
580
582
RubyString [] otherStrings = new RubyString [args .length ];
581
583
582
584
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 ]);
607
586
}
608
587
609
588
return string .count (otherStrings );
0 commit comments