Github user jpountz commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/320#discussion_r166001771
--- Diff: lucene/core/src/java/org/apache/lucene/index/FieldInfos.java ---
@@ -63,21 +60,30 @@ public FieldInfos(FieldInfo[] infos) {
boolean hasNorms = false;
boolean hasDocValues = false;
boolean hasPointValues = false;
-
- TreeMap<Integer, FieldInfo> byNumber = new TreeMap<>();
+
+ int size = 0; // number of elements in byNumberTemp
+ int capacity = 10; // byNumberTemp's capacity
+ FieldInfo[] byNumberTemp = new FieldInfo[capacity];
for (FieldInfo info : infos) {
if (info.number < 0) {
throw new IllegalArgumentException("illegal field number: " +
info.number + " for field " + info.name);
}
- FieldInfo previous = byNumber.put(info.number, info);
+ size = info.number >= size ? info.number+1 : size;
+ if (info.number >= capacity){ //grow array
+ capacity = info.number + 1;
+ byNumberTemp = Arrays.copyOf(byNumberTemp, capacity);
+ }
--- End diff --
can you grow the array exponentially so that it doesn't run in quadratic
time in the worst case? ArrayUtil has some methods that make it easy:
```
if (info.number >= byNumberTemp.length) {
byNumberTemp = ArrayUtil.grow(byNumberTemp, info.number + 1);
}
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]