Skip to content

Commit 6265f31

Browse files
committed
[GR-17457] Optimize DispatchNode class check
PullRequest: truffleruby/2235
2 parents 362a89f + bd8b36f commit 6265f31

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public static DispatchNode getUncached() {
7878
@Child protected ToSymbolNode toSymbol;
7979

8080
protected final ConditionProfile methodMissing;
81-
protected final ConditionProfile isForeignCall;
8281
protected final BranchProfile methodMissingMissing;
8382

8483
protected DispatchNode(
@@ -87,14 +86,12 @@ protected DispatchNode(
8786
LookupMethodNode methodLookup,
8887
CallInternalMethodNode callNode,
8988
ConditionProfile methodMissing,
90-
ConditionProfile isForeignCall,
9189
BranchProfile methodMissingMissing) {
9290
this.config = config;
9391
this.metaclassNode = metaclassNode;
9492
this.methodLookup = methodLookup;
9593
this.callNode = callNode;
9694
this.methodMissing = methodMissing;
97-
this.isForeignCall = isForeignCall;
9895
this.methodMissingMissing = methodMissingMissing;
9996
}
10097

@@ -105,7 +102,6 @@ protected DispatchNode(DispatchConfiguration config) {
105102
LookupMethodNode.create(),
106103
CallInternalMethodNode.create(),
107104
ConditionProfile.create(),
108-
ConditionProfile.create(),
109105
BranchProfile.create());
110106
}
111107

@@ -122,21 +118,21 @@ public Object dispatch(VirtualFrame frame, Object receiver, String methodName, R
122118
}
123119

124120
public Object execute(VirtualFrame frame, Object receiver, String methodName, RubyProc block, Object[] arguments) {
125-
126121
final RubyClass metaclass = metaclassNode.execute(receiver);
127122

128-
if (isForeignCall.profile(metaclass == getContext().getCoreLibrary().truffleInteropForeignClass)) {
129-
return callForeign(receiver, methodName, block, arguments);
130-
}
131-
132123
final InternalMethod method = methodLookup.execute(frame, metaclass, methodName, config);
133124

134125
if (methodMissing.profile(method == null || method.isUndefined())) {
135126
switch (config.missingBehavior) {
136127
case RETURN_MISSING:
137128
return MISSING;
138129
case CALL_METHOD_MISSING:
139-
return callMethodMissing(frame, receiver, methodName, block, arguments);
130+
// Both branches implicitly profile through lazy node creation
131+
if (metaclass == getContext().getCoreLibrary().truffleInteropForeignClass) {
132+
return callForeign(receiver, methodName, block, arguments);
133+
} else {
134+
return callMethodMissing(frame, receiver, methodName, block, arguments);
135+
}
140136
}
141137
}
142138

@@ -240,7 +236,6 @@ protected Uncached(DispatchConfiguration config) {
240236
LookupMethodNodeGen.getUncached(),
241237
CallInternalMethodNodeGen.getUncached(),
242238
ConditionProfile.getUncached(),
243-
ConditionProfile.getUncached(),
244239
BranchProfile.getUncached());
245240
}
246241

0 commit comments

Comments
 (0)