Skip to content

Commit 15e3b70

Browse files
iverasetalevy
authored andcommitted
track the offset of the BytesRef passed to the tree reader (#52704)
1 parent 52ad35a commit 15e3b70

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

server/src/main/java/org/elasticsearch/common/geo/TriangleTreeReader.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class TriangleTreeReader {
5656
private final Tile2D tile2D;
5757
private final Extent extent;
5858
private int treeOffset;
59+
private int docValueOffset;
5960

6061
public TriangleTreeReader(CoordinateEncoder coordinateEncoder) {
6162
this.coordinateEncoder = coordinateEncoder;
@@ -66,6 +67,7 @@ public TriangleTreeReader(CoordinateEncoder coordinateEncoder) {
6667

6768
public void reset(BytesRef bytesRef) throws IOException {
6869
this.input.reset(bytesRef.bytes, bytesRef.offset, bytesRef.length);
70+
docValueOffset = bytesRef.offset;
6971
treeOffset = 0;
7072
}
7173

@@ -87,25 +89,25 @@ public Extent getExtent() {
8789
* returns the X coordinate of the centroid.
8890
*/
8991
public double getCentroidX() {
90-
input.setPosition(0);
92+
input.setPosition(docValueOffset + 0);
9193
return coordinateEncoder.decodeX(input.readInt());
9294
}
9395

9496
/**
9597
* returns the Y coordinate of the centroid.
9698
*/
9799
public double getCentroidY() {
98-
input.setPosition(4);
100+
input.setPosition(docValueOffset + 4);
99101
return coordinateEncoder.decodeY(input.readInt());
100102
}
101103

102104
public DimensionalShapeType getDimensionalShapeType() {
103-
input.setPosition(8);
105+
input.setPosition(docValueOffset + 8);
104106
return DimensionalShapeType.readFrom(input);
105107
}
106108

107109
public double getSumCentroidWeight() {
108-
input.setPosition(9);
110+
input.setPosition(docValueOffset + 9);
109111
return Double.longBitsToDouble(input.readVLong());
110112
}
111113

0 commit comments

Comments
 (0)