FrankChen021 commented on code in PR #5283:
URL: https://github.com/apache/calcite/pull/5283#discussion_r4115151487
##########
core/src/main/java/org/apache/calcite/rex/RexShuttle.java:
##########
@@ -163,15 +163,30 @@ protected RexNode[] visitArray(RexNode[] exprs, boolean
@Nullable [] update) {
*/
protected List<RexNode> visitList(
List<? extends RexNode> exprs, boolean @Nullable [] update) {
- ImmutableList.Builder<RexNode> clonedOperands = ImmutableList.builder();
+ ImmutableList.@Nullable Builder<RexNode> clonedOperands = null;
+ int i = 0;
for (RexNode operand : exprs) {
RexNode clonedOperand = operand.accept(this);
- if ((clonedOperand != operand) && (update != null)) {
- update[0] = true;
+ if (clonedOperand != operand && clonedOperands == null) {
+ clonedOperands = ImmutableList.builder();
+ clonedOperands.addAll(exprs.subList(0, i));
+ if (update != null) {
+ update[0] = true;
+ }
+ }
+ if (clonedOperands != null) {
+ clonedOperands.add(clonedOperand);
}
- clonedOperands.add(clonedOperand);
+ i++;
}
- return clonedOperands.build();
+ if (clonedOperands != null) {
+ return clonedOperands.build();
+ }
+ if (exprs instanceof ImmutableList) {
+ //noinspection unchecked
+ return (List<RexNode>) exprs;
+ }
+ return ImmutableList.copyOf(exprs);
Review Comment:
Updated to use `ImmutableList.copyOf(exprs)`. It reuses a full
`ImmutableList` and compacts partial views; a partial-view test was added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]