Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions presto-main/src/main/java/io/prestosql/sql/gen/BytecodeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,7 @@ public static BytecodeNode generateFullInvocation(
}
else {
BytecodeNode argument = argumentCompilers.get(i).apply(Optional.empty());
if (argument instanceof InputReferenceNode) {
argumentConventions.add(BLOCK_POSITION);
}
else if (functionMetadata.getArgumentDefinitions().get(i).isNullable()) {
// a Java function can only have 255 arguments, so if the count is high use boxed nullable instead of the more efficient null flag
argumentConventions.add(argumentCompilers.size() > 100 ? BOXED_NULLABLE : NULL_FLAG);
}
else {
argumentConventions.add(NEVER_NULL);
}
argumentConventions.add(getPreferredArgumentConvention(argument, argumentCompilers.size(), functionMetadata.getArgumentDefinitions().get(i).isNullable()));
arguments.add(argument);
}
}
Expand Down Expand Up @@ -355,6 +346,21 @@ else if (type == ConnectorSession.class) {
return block;
}

private static InvocationArgumentConvention getPreferredArgumentConvention(BytecodeNode argument, int argumentCount, boolean nullable)
{
// a Java function can only have 255 arguments, so if the count is low use block position or boxed nullable as they are more efficient
if (argumentCount <= 100) {
if (argument instanceof InputReferenceNode) {
return BLOCK_POSITION;
}
if (nullable) {
return NULL_FLAG;
}
}

return nullable ? BOXED_NULLABLE : NEVER_NULL;
}

public static BytecodeBlock unboxPrimitiveIfNecessary(Scope scope, Class<?> boxedType)
{
BytecodeBlock block = new BytecodeBlock();
Expand Down