|
19 | 19 | import com.oracle.truffle.api.profiles.ConditionProfile;
|
20 | 20 | import org.truffleruby.core.array.ArrayUtils;
|
21 | 21 | import org.truffleruby.core.cast.NameToJavaStringNode;
|
| 22 | +import org.truffleruby.core.cast.ToSymbolNode; |
22 | 23 | import org.truffleruby.core.exception.ExceptionOperations;
|
23 | 24 | import org.truffleruby.core.klass.RubyClass;
|
24 | 25 | import org.truffleruby.core.proc.RubyProc;
|
25 |
| -import org.truffleruby.core.string.RubyString; |
26 | 26 | import org.truffleruby.core.symbol.RubySymbol;
|
27 | 27 | import org.truffleruby.language.FrameSendingNode;
|
28 |
| -import org.truffleruby.language.RubyGuards; |
29 | 28 | import org.truffleruby.language.RubyRootNode;
|
30 | 29 | import org.truffleruby.language.arguments.RubyArguments;
|
31 | 30 | import org.truffleruby.language.control.RaiseException;
|
@@ -81,6 +80,7 @@ public static DispatchNode getUncached() {
|
81 | 80 | @Child protected NameToJavaStringNode nameToString;
|
82 | 81 | @Child protected CallForeignMethodNode callForeign;
|
83 | 82 | @Child protected DispatchNode callMethodMissing;
|
| 83 | + @Child protected ToSymbolNode toSymbol; |
84 | 84 |
|
85 | 85 | protected final ConditionProfile nameIsString;
|
86 | 86 | protected final ConditionProfile methodMissing;
|
@@ -226,16 +226,12 @@ protected Object callMethodMissingNode(
|
226 | 226 | return callMethodMissing.execute(null, receiver, "method_missing", block, arguments);
|
227 | 227 | }
|
228 | 228 |
|
229 |
| - private RubySymbol nameToSymbol(Object methodName) { |
230 |
| - if (methodName instanceof RubySymbol) { |
231 |
| - return (RubySymbol) methodName; |
232 |
| - } else if (RubyGuards.isRubyString(methodName)) { |
233 |
| - return getContext().getSymbol(((RubyString) methodName).rope); |
234 |
| - } else if (methodName instanceof String) { |
235 |
| - return getContext().getSymbol((String) methodName); |
236 |
| - } else { |
237 |
| - throw CompilerDirectives.shouldNotReachHere(); |
| 229 | + protected RubySymbol nameToSymbol(Object methodName) { |
| 230 | + if (toSymbol == null) { |
| 231 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 232 | + toSymbol = insert(ToSymbolNode.create()); |
238 | 233 | }
|
| 234 | + return toSymbol.execute(methodName); |
239 | 235 | }
|
240 | 236 |
|
241 | 237 | /** This will be called from the {@link CallInternalMethodNode} child whenever it creates a new
|
@@ -322,6 +318,15 @@ protected Object callMethodMissingNode(
|
322 | 318 | return callMethodMissing.execute(null, receiver, "method_missing", block, arguments);
|
323 | 319 | }
|
324 | 320 |
|
| 321 | + @Override |
| 322 | + protected RubySymbol nameToSymbol(Object methodName) { |
| 323 | + if (toSymbol == null) { |
| 324 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 325 | + toSymbol = insert(ToSymbolNode.getUncached()); |
| 326 | + } |
| 327 | + return toSymbol.execute(methodName); |
| 328 | + } |
| 329 | + |
325 | 330 | @Override
|
326 | 331 | public NodeCost getCost() {
|
327 | 332 | return NodeCost.MEGAMORPHIC;
|
|
0 commit comments