Skip to content

Commit 3d219bd

Browse files
committed
The empty keyword descriptor can be static
1 parent bca4203 commit 3d219bd

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
import org.truffleruby.language.arguments.ArgumentsDescriptor;
9191
import org.truffleruby.language.arguments.EmptyArgumentsDescriptor;
9292
import org.truffleruby.language.arguments.KeywordArgumentsDescriptor;
93+
import org.truffleruby.language.arguments.KeywordArgumentsDescriptorManager;
9394
import org.truffleruby.language.arguments.RubyArguments;
9495
import org.truffleruby.language.backtrace.Backtrace;
9596
import org.truffleruby.language.constants.GetConstantNode;
@@ -320,7 +321,7 @@ protected Object sendWithoutCExtLock(
320321
dispatchNode, ownedProfile);
321322
} else {
322323
return sendWithoutCExtLock(frame, receiver, method, block,
323-
getLanguage().keywordArgumentsDescriptorManager.EMPTY, args,
324+
KeywordArgumentsDescriptorManager.EMPTY, args,
324325
dispatchNode, ownedProfile);
325326
}
326327
}

src/main/java/org/truffleruby/language/arguments/KeywordArgumentsDescriptorManager.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@
1616

1717
public class KeywordArgumentsDescriptorManager {
1818

19+
public static final KeywordArgumentsDescriptor EMPTY = new KeywordArgumentsDescriptor(
20+
StringUtils.EMPTY_STRING_ARRAY);
21+
1922
private final WeakValueCache<Key, KeywordArgumentsDescriptor> CANONICAL_KEYWORD_DESCRIPTORS = new WeakValueCache<>();
2023

21-
public final KeywordArgumentsDescriptor EMPTY = getArgumentsDescriptor(StringUtils.EMPTY_STRING_ARRAY);
24+
public KeywordArgumentsDescriptorManager() {
25+
CANONICAL_KEYWORD_DESCRIPTORS.put(new Key(StringUtils.EMPTY_STRING_ARRAY), EMPTY);
26+
}
2227

2328
public KeywordArgumentsDescriptor getArgumentsDescriptor(String[] keywords) {
2429
final Key key = new Key(keywords);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.truffleruby.language.RubyRootNode;
2929
import org.truffleruby.language.arguments.ArgumentsDescriptor;
3030
import org.truffleruby.language.arguments.EmptyArgumentsDescriptor;
31+
import org.truffleruby.language.arguments.KeywordArgumentsDescriptorManager;
3132
import org.truffleruby.language.arguments.RubyArguments;
3233
import org.truffleruby.language.control.RaiseException;
3334
import org.truffleruby.language.methods.CallForeignMethodNode;
@@ -159,7 +160,7 @@ public Object callWithKeywords(Object receiver, String method, Object arg1, Ruby
159160
final Object[] rubyArgs = RubyArguments.allocate(2);
160161
RubyArguments.setSelf(rubyArgs, receiver);
161162
RubyArguments.setBlock(rubyArgs, nil);
162-
RubyArguments.setDescriptor(rubyArgs, getLanguage().keywordArgumentsDescriptorManager.EMPTY);
163+
RubyArguments.setDescriptor(rubyArgs, KeywordArgumentsDescriptorManager.EMPTY);
163164
RubyArguments.setArgument(rubyArgs, 0, arg1);
164165
RubyArguments.setArgument(rubyArgs, 1, keywords);
165166
return dispatch(null, receiver, method, rubyArgs);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
2020
import org.truffleruby.language.arguments.EmptyArgumentsDescriptor;
21+
import org.truffleruby.language.arguments.KeywordArgumentsDescriptor;
22+
import org.truffleruby.language.arguments.KeywordArgumentsDescriptorManager;
2123

2224
/** A literal call site in Ruby code: one of foo(), super or yield. */
2325
public abstract class LiteralCallNode extends RubyContextSourceNode {
@@ -60,7 +62,7 @@ protected ArgumentsDescriptor getArgumentsDescriptorAndCheckRuby2KeywordsHash(Ob
6062

6163
RubyHash unmarked = copyHashAndSetRuby2KeywordsNode.execute((RubyHash) lastArgument, false);
6264
ArrayUtils.setLast(args, unmarked);
63-
return getLanguage().keywordArgumentsDescriptorManager.EMPTY;
65+
return KeywordArgumentsDescriptorManager.EMPTY;
6466
} else {
6567
if (!notRuby2KeywordsHashProfile) {
6668
CompilerDirectives.transferToInterpreterAndInvalidate();

src/main/java/org/truffleruby/parser/MethodTranslator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.truffleruby.language.SourceIndexLength;
2828
import org.truffleruby.language.arguments.ArgumentsDescriptor;
2929
import org.truffleruby.language.arguments.EmptyArgumentsDescriptor;
30+
import org.truffleruby.language.arguments.KeywordArgumentsDescriptorManager;
3031
import org.truffleruby.language.arguments.MissingArgumentBehavior;
3132
import org.truffleruby.language.arguments.ReadPreArgumentNode;
3233
import org.truffleruby.language.arguments.ShouldDestructureNode;
@@ -498,7 +499,7 @@ public RubyNode visitZSuperNode(ZSuperParseNode node) {
498499
final SequenceNode reloadSequence = (SequenceNode) reloadTranslator.visitArgsNode(argsNode);
499500

500501
final ArgumentsDescriptor descriptor = argsNode.hasKwargs()
501-
? language.keywordArgumentsDescriptorManager.EMPTY
502+
? KeywordArgumentsDescriptorManager.EMPTY
502503
: EmptyArgumentsDescriptor.INSTANCE;
503504
final RubyNode arguments = new ReadZSuperArgumentsNode(
504505
reloadTranslator.getRestParameterIndex(),

0 commit comments

Comments
 (0)