Skip to content

Commit ad26094

Browse files
author
Nicolas Laurent
committed
use ToSymbolNode in dispatch
1 parent 30956fb commit ad26094

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/main/java/org/truffleruby/core/cast/ToSymbolNode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public static ToSymbolNode create() {
2929
return ToSymbolNodeGen.create();
3030
}
3131

32+
public static ToSymbolNode getUncached() {
33+
return ToSymbolNodeGen.getUncached();
34+
}
35+
3236
public abstract RubySymbol execute(Object object);
3337

3438
@Specialization

src/main/java/org/truffleruby/language/dispatch/DispatchNode.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919
import com.oracle.truffle.api.profiles.ConditionProfile;
2020
import org.truffleruby.core.array.ArrayUtils;
2121
import org.truffleruby.core.cast.NameToJavaStringNode;
22+
import org.truffleruby.core.cast.ToSymbolNode;
2223
import org.truffleruby.core.exception.ExceptionOperations;
2324
import org.truffleruby.core.klass.RubyClass;
2425
import org.truffleruby.core.proc.RubyProc;
25-
import org.truffleruby.core.string.RubyString;
2626
import org.truffleruby.core.symbol.RubySymbol;
2727
import org.truffleruby.language.FrameSendingNode;
28-
import org.truffleruby.language.RubyGuards;
2928
import org.truffleruby.language.RubyRootNode;
3029
import org.truffleruby.language.arguments.RubyArguments;
3130
import org.truffleruby.language.control.RaiseException;
@@ -81,6 +80,7 @@ public static DispatchNode getUncached() {
8180
@Child protected NameToJavaStringNode nameToString;
8281
@Child protected CallForeignMethodNode callForeign;
8382
@Child protected DispatchNode callMethodMissing;
83+
@Child protected ToSymbolNode toSymbol;
8484

8585
protected final ConditionProfile nameIsString;
8686
protected final ConditionProfile methodMissing;
@@ -226,16 +226,12 @@ protected Object callMethodMissingNode(
226226
return callMethodMissing.execute(null, receiver, "method_missing", block, arguments);
227227
}
228228

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());
238233
}
234+
return toSymbol.execute(methodName);
239235
}
240236

241237
/** This will be called from the {@link CallInternalMethodNode} child whenever it creates a new
@@ -322,6 +318,15 @@ protected Object callMethodMissingNode(
322318
return callMethodMissing.execute(null, receiver, "method_missing", block, arguments);
323319
}
324320

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+
325330
@Override
326331
public NodeCost getCost() {
327332
return NodeCost.MEGAMORPHIC;

0 commit comments

Comments
 (0)