Skip to content

Commit fb4116a

Browse files
chrisseatonMattAlp
andcommitted
If a call target supplier is fulfilled, just use it
Co-authored-by: Matthew Alt <[email protected]>
1 parent 7a9dd96 commit fb4116a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/main/java/org/truffleruby/collections/CachedSupplier.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public CachedSupplier(Supplier<T> supplier) {
2222

2323
@Override
2424
public T get() {
25-
if (value != null) {
25+
if (isAvailable()) {
2626
return value;
2727
}
2828
synchronized (this) {
@@ -33,4 +33,9 @@ public T get() {
3333
return value;
3434
}
3535
}
36+
37+
public boolean isAvailable() {
38+
return value != null;
39+
}
40+
3641
}

src/main/java/org/truffleruby/language/methods/InternalMethod.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ private InternalMethod(
171171
this.proc = proc;
172172
this.callTarget = callTarget;
173173
this.callTargetSupplier = callTargetSupplier;
174+
175+
/* If the call target supplier has already been run, then don't wait until the first time the InternalMethod is
176+
* asked for the call target, because this would be a deoptimisation in getCallTarget. */
177+
178+
if (callTarget == null && callTargetSupplier != null && callTargetSupplier.isAvailable()) {
179+
this.callTarget = callTargetSupplier.get();
180+
}
174181
}
175182

176183
public SharedMethodInfo getSharedMethodInfo() {

0 commit comments

Comments
 (0)