Skip to content

Commit 20dccee

Browse files
committed
Extract asserts in RubyArguments.pack() in their own method
* So these asserts can be reused without also creating an unused Object[].
1 parent ad5cede commit 20dccee

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,30 @@ public static Object[] pack(
6565
Object self,
6666
Object block,
6767
Object[] arguments) {
68+
assert assertValues(callerFrameOrVariables, method, declarationContext, self, block, arguments);
69+
70+
final Object[] packed = new Object[RUNTIME_ARGUMENT_COUNT + arguments.length];
71+
72+
packed[ArgumentIndicies.DECLARATION_FRAME.ordinal()] = declarationFrame;
73+
packed[ArgumentIndicies.CALLER_FRAME_OR_VARIABLES.ordinal()] = callerFrameOrVariables;
74+
packed[ArgumentIndicies.METHOD.ordinal()] = method;
75+
packed[ArgumentIndicies.DECLARATION_CONTEXT.ordinal()] = declarationContext;
76+
packed[ArgumentIndicies.FRAME_ON_STACK_MARKER.ordinal()] = frameOnStackMarker;
77+
packed[ArgumentIndicies.SELF.ordinal()] = self;
78+
packed[ArgumentIndicies.BLOCK.ordinal()] = block;
79+
80+
ArrayUtils.arraycopy(arguments, 0, packed, RUNTIME_ARGUMENT_COUNT, arguments.length);
81+
82+
return packed;
83+
}
84+
85+
public static boolean assertValues(
86+
Object callerFrameOrVariables,
87+
InternalMethod method,
88+
DeclarationContext declarationContext,
89+
Object self,
90+
Object block,
91+
Object[] arguments) {
6892
assert method != null;
6993
assert declarationContext != null;
7094
assert self != null;
@@ -76,26 +100,14 @@ public static Object[] pack(
76100
callerFrameOrVariables instanceof SpecialVariableStorage ||
77101
callerFrameOrVariables instanceof FrameAndVariables;
78102

79-
final Object[] packed = new Object[RUNTIME_ARGUMENT_COUNT + arguments.length];
80-
81-
packed[ArgumentIndicies.DECLARATION_FRAME.ordinal()] = declarationFrame;
82-
packed[ArgumentIndicies.CALLER_FRAME_OR_VARIABLES.ordinal()] = callerFrameOrVariables;
83-
packed[ArgumentIndicies.METHOD.ordinal()] = method;
84-
packed[ArgumentIndicies.DECLARATION_CONTEXT.ordinal()] = declarationContext;
85-
packed[ArgumentIndicies.FRAME_ON_STACK_MARKER.ordinal()] = frameOnStackMarker;
86-
packed[ArgumentIndicies.SELF.ordinal()] = self;
87-
88103
/* The block in the arguments array is always either a Nil or RubyProc. The provision of Nil if the caller
89104
* doesn't want to provide a block is done at the caller, because it will know the type of values within its
90105
* compilation unit.
91106
*
92107
* When you read the block back out in the callee, you'll therefore get a Nil or RubyProc. */
93108
assert block instanceof Nil || block instanceof RubyProc : block;
94-
packed[ArgumentIndicies.BLOCK.ordinal()] = block;
95-
96-
ArrayUtils.arraycopy(arguments, 0, packed, RUNTIME_ARGUMENT_COUNT, arguments.length);
97109

98-
return packed;
110+
return true;
99111
}
100112

101113
// Getters

0 commit comments

Comments
 (0)