2222import org .apache .lucene .index .SegmentWriteState ;
2323import org .apache .lucene .index .Terms ;
2424import org .apache .lucene .index .TermsEnum ;
25- import org .apache .lucene .internal .hppc .IntIntHashMap ;
2625import org .apache .lucene .util .BytesRef ;
2726import org .elasticsearch .common .util .FeatureFlag ;
2827
@@ -63,22 +62,18 @@ public FieldsProducer fieldsProducer(SegmentReadState state) throws IOException
6362 static final class TrackingLengthFieldsConsumer extends FieldsConsumer {
6463 final SegmentWriteState state ;
6564 final FieldsConsumer in ;
66- final IntIntHashMap termsBytesPerField ;
65+ final long [] totalBytes ;
6766
6867 TrackingLengthFieldsConsumer (SegmentWriteState state , FieldsConsumer in ) {
6968 this .state = state ;
7069 this .in = in ;
71- this .termsBytesPerField = new IntIntHashMap ( state . fieldInfos . size ()) ;
70+ this .totalBytes = new long [ 1 ] ;
7271 }
7372
7473 @ Override
7574 public void write (Fields fields , NormsProducer norms ) throws IOException {
76- in .write (new TrackingLengthFields (fields , termsBytesPerField , state .fieldInfos ), norms );
77- long totalBytes = 0 ;
78- for (int bytes : termsBytesPerField .values ) {
79- totalBytes += bytes ;
80- }
81- state .segmentInfo .putAttribute (IN_MEMORY_POSTINGS_BYTES_KEY , Long .toString (totalBytes ));
75+ in .write (new TrackingLengthFields (fields , totalBytes , state .fieldInfos ), norms );
76+ state .segmentInfo .putAttribute (IN_MEMORY_POSTINGS_BYTES_KEY , Long .toString (totalBytes [0 ]));
8277 }
8378
8479 @ Override
@@ -88,12 +83,12 @@ public void close() throws IOException {
8883 }
8984
9085 static final class TrackingLengthFields extends FilterLeafReader .FilterFields {
91- final IntIntHashMap termsBytesPerField ;
86+ final long [] totalBytes ;
9287 final FieldInfos fieldInfos ;
9388
94- TrackingLengthFields (Fields in , IntIntHashMap termsBytesPerField , FieldInfos fieldInfos ) {
89+ TrackingLengthFields (Fields in , long [] totalBytes , FieldInfos fieldInfos ) {
9590 super (in );
96- this .termsBytesPerField = termsBytesPerField ;
91+ this .totalBytes = totalBytes ;
9792 this .fieldInfos = fieldInfos ;
9893 }
9994
@@ -103,11 +98,7 @@ public Terms terms(String field) throws IOException {
10398 if (terms == null ) {
10499 return null ;
105100 }
106- int fieldNum = fieldInfos .fieldInfo (field ).number ;
107- return new TrackingLengthTerms (
108- terms ,
109- bytes -> termsBytesPerField .put (fieldNum , Math .max (termsBytesPerField .getOrDefault (fieldNum , 0 ), bytes ))
110- );
101+ return new TrackingLengthTerms (terms , bytes -> totalBytes [0 ] += bytes );
111102 }
112103 }
113104
0 commit comments