Skip to content

Commit af6efdb

Browse files
committed
Review fixes
1 parent b19aed7 commit af6efdb

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/ExponentialHistogramArrayBlock.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,14 @@ private BlockBackedHistogram(BytesRef bytes) {
204204
}
205205

206206
static BytesRef encode(ExponentialHistogram histogram, BytesRef growableBuffer) {
207+
assert growableBuffer.offset == 0;
208+
207209
int totalSize = 1;
208210

209211
resizeIfRequired(growableBuffer, totalSize);
210-
BytesRef result = new BytesRef();
211-
result.bytes = growableBuffer.bytes;
212-
result.offset = growableBuffer.offset;
213-
result.length = totalSize;
212+
BytesRef result = new BytesRef(growableBuffer.bytes, 0, totalSize);
214213

215-
ByteBuffer buffer = ByteBuffer.wrap(result.bytes, result.offset, result.length).order(ByteOrder.LITTLE_ENDIAN);
214+
ByteBuffer buffer = ByteBuffer.wrap(result.bytes, 0, result.length).order(ByteOrder.LITTLE_ENDIAN);
216215
buffer.put(SCALE_OFFSET, (byte) histogram.scale());
217216

218217
return result;
@@ -222,7 +221,7 @@ private static void resizeIfRequired(BytesRef growableBuffer, int totalSize) {
222221
if (growableBuffer.length >= totalSize) {
223222
return;
224223
}
225-
growableBuffer.length = Math.max(32, growableBuffer.length);
224+
assert growableBuffer.length > 0;
226225
while (growableBuffer.length < totalSize) {
227226
growableBuffer.length *= 2;
228227
}

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/ExponentialHistogramBlockBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
public class ExponentialHistogramBlockBuilder implements Block.Builder {
1616

17+
private static final int INITIAL_SCRATCH_SIZE = 256;
18+
1719
private final BytesRefBlock.Builder encodedHistogramsBuilder;
1820

1921
private final BytesRef tempScratch;
@@ -22,7 +24,7 @@ public class ExponentialHistogramBlockBuilder implements Block.Builder {
2224

2325
ExponentialHistogramBlockBuilder(int estimatedSize, BlockFactory blockFactory) {
2426
this.encodedHistogramsBuilder = blockFactory.newBytesRefBlockBuilder(estimatedSize);
25-
this.tempScratch = new BytesRef(new byte[256], 0, 256);
27+
this.tempScratch = new BytesRef(new byte[INITIAL_SCRATCH_SIZE], 0, INITIAL_SCRATCH_SIZE);
2628
}
2729

2830
public ExponentialHistogramBlockBuilder append(@Nullable ExponentialHistogram value) {

0 commit comments

Comments
 (0)