Github user jpountz commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/320#discussion_r166005204
--- Diff: lucene/core/src/java/org/apache/lucene/index/FieldInfos.java ---
@@ -96,25 +102,19 @@ public FieldInfos(FieldInfo[] infos) {
this.hasNorms = hasNorms;
this.hasDocValues = hasDocValues;
this.hasPointValues = hasPointValues;
- Integer max = byNumber.isEmpty() ? null : byNumber.lastKey();
-
- // Only usee TreeMap in the very sparse case (< 1/16th of the numbers
are used),
- // because TreeMap uses ~ 64 (32 bit JVM) or 120 (64 bit JVM w/o
compressed oops)
- // overall bytes per entry, but array uses 4 (32 bit JMV) or 8
- // (64 bit JVM w/o compressed oops):
- if (max != null && max < ArrayUtil.MAX_ARRAY_LENGTH && max <
16L*byNumber.size()) {
- // Pull infos into an arraylist to avoid holding a reference to the
TreeMap
- values = Collections.unmodifiableCollection(new
ArrayList<>(byNumber.values()));
- byNumberMap = null;
- byNumberTable = new FieldInfo[max+1];
- for (Map.Entry<Integer,FieldInfo> entry : byNumber.entrySet()) {
- byNumberTable[entry.getKey()] = entry.getValue();
+
+ List<FieldInfo> valuesTemp = new ArrayList<>();
+ if (size > 0){
+ byNumber = new FieldInfo[size];
+ for(int i=0; i<size; i++){
+ byNumber[i] = byNumberTemp[i];
+ if (byNumberTemp[i] != null)
+ valuesTemp.add(byNumberTemp[i]);
}
} else {
- byNumberMap = byNumber;
- values = Collections.unmodifiableCollection(byNumber.values());
- byNumberTable = null;
+ byNumber = null;
--- End diff --
It seems a bit trappy to use `null` to represent empty arrays, especially
since the `fieldInfo` method doesn't test for nullity?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]