This is an automated email from the ASF dual-hosted git repository. vladimirsitnikov pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git
commit fb2a02fb78f4e5b9b887645651b4b285ed68dacd Author: Vladimir Sitnikov <sitnikov.vladi...@gmail.com> AuthorDate: Fri Sep 4 23:39:27 2020 +0300 Remove ArrayList allocation from Mappings#bijection, and add helpful message in case NPE is thrown bijection requires all indices from [0..targets.size()-1) to be mapped to non-null, and NPE was thrown if that is not the case. The change adds extra message, so it is easier to see what aas the mapping. --- .../main/java/org/apache/calcite/util/mapping/Mappings.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java b/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java index 88d2c7e..269c6cd 100644 --- a/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java +++ b/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java @@ -426,11 +426,15 @@ public abstract class Mappings { * * <p>Throws if sources and targets are not one to one. */ public static Mapping bijection(Map<Integer, Integer> targets) { - final List<Integer> targetList = new ArrayList<>(); + int[] ints = new int[targets.size()]; for (int i = 0; i < targets.size(); i++) { - targetList.add(targets.get(i)); + Integer value = targets.get(i); + if (value == null) { + throw new NullPointerException("Index " + i + " is not mapped in " + targets); + } + ints[i] = value; } - return new Permutation(Ints.toArray(targetList)); + return new Permutation(ints); } /**