Browse Source

Remove needless array indirection in AbstractInternalTerms (#126830) (#126839)

Obviously just a single count, make it a plain field like the counter next to it.
Armin Braun 5 tháng trước cách đây
mục cha
commit
132187edc0

+ 5 - 5
server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/AbstractInternalTerms.java

@@ -220,7 +220,7 @@ public abstract class AbstractInternalTerms<A extends AbstractInternalTerms<A, B
         private final int size;
 
         private long sumDocCountError = 0;
-        private final long[] otherDocCount = new long[] { 0 };
+        private long otherDocCount = 0;
         private A referenceTerms = null;
         /*
          * Buckets returned by a partial reduce or a shard response are sorted by key since {@link Version#V_7_10_0}.
@@ -255,7 +255,7 @@ public abstract class AbstractInternalTerms<A extends AbstractInternalTerms<A, B
             } else if (thisReduceOrder != getOrder() && thisReduceOrder.equals(terms.getReduceOrder()) == false) {
                 thisReduceOrder = getOrder();
             }
-            otherDocCount[0] += terms.getSumOfOtherDocCounts();
+            otherDocCount += terms.getSumOfOtherDocCounts();
             final long thisAggDocCountError = getDocCountError(terms);
             setDocCountError(thisAggDocCountError);
             if (sumDocCountError != -1) {
@@ -297,14 +297,14 @@ public abstract class AbstractInternalTerms<A extends AbstractInternalTerms<A, B
                         reduceContext.consumeBucketsAndMaybeBreak(1);
                         result.add(bucket.reduced(AbstractInternalTerms.this::reduceBucket, reduceContext));
                     } else {
-                        otherDocCount[0] += bucket.getDocCount();
+                        otherDocCount += bucket.getDocCount();
                     }
                 });
             } else if (reduceContext.isFinalReduce()) {
                 TopBucketBuilder<B> top = TopBucketBuilder.build(
                     getRequiredSize(),
                     getOrder(),
-                    removed -> otherDocCount[0] += removed.getDocCount(),
+                    removed -> otherDocCount += removed.getDocCount(),
                     AbstractInternalTerms.this::reduceBucket,
                     reduceContext
                 );
@@ -334,7 +334,7 @@ public abstract class AbstractInternalTerms<A extends AbstractInternalTerms<A, B
             if (sumDocCountError != -1) {
                 docCountError = size == 1 ? 0 : sumDocCountError;
             }
-            return create(name, result, reduceContext.isFinalReduce() ? getOrder() : thisReduceOrder, docCountError, otherDocCount[0]);
+            return create(name, result, reduceContext.isFinalReduce() ? getOrder() : thisReduceOrder, docCountError, otherDocCount);
         }
 
         private BucketOrder getThisReduceOrder() {