diff --git a/presto-main/src/main/java/io/prestosql/sql/gen/BytecodeUtils.java b/presto-main/src/main/java/io/prestosql/sql/gen/BytecodeUtils.java index c4bc484599d7..d32fa29bde08 100644 --- a/presto-main/src/main/java/io/prestosql/sql/gen/BytecodeUtils.java +++ b/presto-main/src/main/java/io/prestosql/sql/gen/BytecodeUtils.java @@ -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); } } @@ -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();