Skip to content

Commit 6eb25c4

Browse files
committed
reduce bytes used when serializing Extent (#52549)
This commit reflects comments made by Adrien in #50834 surrounding the Extent serialization. it re-orders and negates a few values in order to save more space
1 parent 15e3b70 commit 6eb25c4

File tree

1 file changed

+20
-16
lines changed
  • server/src/main/java/org/elasticsearch/common/geo

1 file changed

+20
-16
lines changed

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

+20-16
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,31 @@ static void readFromCompressed(ByteArrayDataInput input, Extent extent) {
115115
posRight = Integer.MIN_VALUE;
116116
break;
117117
case POSITIVE_SET:
118-
posRight = input.readVInt();
119-
posLeft = Math.toIntExact(posRight - input.readVLong());
118+
posLeft = input.readVInt();
119+
posRight = Math.toIntExact(input.readVLong() + posLeft);
120120
negLeft = Integer.MAX_VALUE;
121121
negRight = Integer.MIN_VALUE;
122122
break;
123123
case NEGATIVE_SET:
124-
negRight = input.readInt();
124+
negRight = -input.readVInt();
125125
negLeft = Math.toIntExact(negRight - input.readVLong());
126126
posLeft = Integer.MAX_VALUE;
127127
posRight = Integer.MIN_VALUE;
128128
break;
129129
case CROSSES_LAT_AXIS:
130-
posRight = input.readInt();
131-
negLeft = Math.toIntExact(posRight - input.readVLong());
130+
posRight = input.readVInt();
131+
negLeft = -input.readVInt();
132132
posLeft = 0;
133133
negRight = 0;
134134
break;
135-
default:
136-
posRight = input.readVInt();
137-
posLeft = Math.toIntExact(posRight - input.readVLong());
138-
negRight = input.readInt();
135+
case ALL_SET:
136+
posLeft = input.readVInt();
137+
posRight = Math.toIntExact(input.readVLong() + posLeft);
138+
negRight = -input.readVInt();
139139
negLeft = Math.toIntExact(negRight - input.readVLong());
140140
break;
141+
default:
142+
throw new IllegalArgumentException("invalid extent values-set byte read [" + type + "]");
141143
}
142144
extent.reset(top, bottom, negLeft, negRight, posLeft, posRight);
143145
}
@@ -165,23 +167,25 @@ void writeCompressed(ByteBuffersDataOutput output) throws IOException {
165167
switch (type) {
166168
case NONE_SET : break;
167169
case POSITIVE_SET:
168-
output.writeVInt(this.posRight);
170+
output.writeVInt(this.posLeft);
169171
output.writeVLong((long) this.posRight - this.posLeft);
170172
break;
171173
case NEGATIVE_SET:
172-
output.writeInt(this.negRight);
174+
output.writeVInt(-this.negRight);
173175
output.writeVLong((long) this.negRight - this.negLeft);
174176
break;
175177
case CROSSES_LAT_AXIS:
176-
output.writeInt(this.posRight);
177-
output.writeVLong((long) this.posRight - this.negLeft);
178-
break;
179-
default:
180178
output.writeVInt(this.posRight);
179+
output.writeVInt(-this.negLeft);
180+
break;
181+
case ALL_SET:
182+
output.writeVInt(this.posLeft);
181183
output.writeVLong((long) this.posRight - this.posLeft);
182-
output.writeInt(this.negRight);
184+
output.writeVInt(-this.negRight);
183185
output.writeVLong((long) this.negRight - this.negLeft);
184186
break;
187+
default:
188+
throw new IllegalArgumentException("invalid extent values-set byte read [" + type + "]");
185189
}
186190
}
187191

0 commit comments

Comments
 (0)