lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpountz <...@git.apache.org>
Subject [GitHub] lucene-solr pull request #320: LUCENE-8033: FieldInfos always use dense enco...
Date Mon, 05 Feb 2018 15:29:50 GMT
Github user jpountz commented on a diff in the pull request:

    https://github.com/apache/lucene-solr/pull/320#discussion_r166003726
  
    --- 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;
         }
    +    values = Collections.unmodifiableCollection(valuesTemp);
    --- End diff --
    
    Let's maybe allow empty slots at the end of the array list to be collected by doing something
like this?
    
    ```java
    values = Collections.unmodifiableCollection(Arrays.asList(valuesTemp.toArray(new FieldInfo[0])));
    ```


---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Mime
View raw message