From 64973957f0de71275c1b26b138eb0b8cd8565064 Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Mon, 25 Nov 2019 13:36:03 -0800 Subject: [PATCH] reduce Extent serialization to 16 bytes Extent was serializing 6 numbers, but that was unnecessary since two can be derived. --- .../org/elasticsearch/common/geo/Extent.java | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/common/geo/Extent.java b/server/src/main/java/org/elasticsearch/common/geo/Extent.java index 46991c8a2801f..bc65ffd345950 100644 --- a/server/src/main/java/org/elasticsearch/common/geo/Extent.java +++ b/server/src/main/java/org/elasticsearch/common/geo/Extent.java @@ -30,7 +30,7 @@ * {@link GeometryTreeWriter} and {@link EdgeTreeWriter}. */ public class Extent implements Writeable { - static final int WRITEABLE_SIZE_IN_BYTES = 24; + static final int WRITEABLE_SIZE_IN_BYTES = 16; public final int top; public final int bottom; @@ -49,7 +49,31 @@ public Extent(int top, int bottom, int negLeft, int negRight, int posLeft, int p } Extent(StreamInput input) throws IOException { - this(input.readInt(), input.readInt(), input.readInt(), input.readInt(), input.readInt(), input.readInt()); + this.top = input.readInt(); + this.bottom = input.readInt(); + + int left = input.readInt(); + int right = input.readInt(); + + int negLeft = Integer.MAX_VALUE; + int negRight = Integer.MIN_VALUE; + int posLeft = Integer.MAX_VALUE; + int posRight = Integer.MIN_VALUE; + if (left < 0 && right < 0) { + negLeft = left; + negRight = right; + } else if (left < 0) { + negLeft = negRight = left; + posLeft = posRight = right; + } else { + posLeft = left; + posRight = right; + } + + this.negLeft = negLeft; + this.negRight = negRight; + this.posLeft = posLeft; + this.posRight = posRight; } /** @@ -128,10 +152,8 @@ public int maxX() { public void writeTo(StreamOutput out) throws IOException { out.writeInt(top); out.writeInt(bottom); - out.writeInt(negLeft); - out.writeInt(negRight); - out.writeInt(posLeft); - out.writeInt(posRight); + out.writeInt(minX()); + out.writeInt(maxX()); } @Override