jpountz commented on code in PR #12357:
URL: https://github.com/apache/lucene/pull/12357#discussion_r1223169917
##########
lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java:
##########
@@ -176,11 +179,17 @@ public final byte readByte(long pos) throws IOException {
public final short readShort(long pos) throws IOException {
long index = pos - bufferStart;
if (index < 0 || index >= buffer.limit() - 1) {
- bufferStart = pos;
+ // if we're moving backwards, then try and fill up the previous page
rather than
+ // starting again at the current pos, to avoid successive backwards
reads reloading
+ // the same data over and over again
+ bufferStart = index < 0 ? Math.min(pos, Math.max(0, bufferStart -
bufferSize)) : pos;
+ if (bufferStart + bufferSize - pos <= 1) {
Review Comment:
If I'm not mistaken, this can only happen when `index < 0` so maybe we
should rewrite the above ternary expression into an if/else block and only have
the above check when `index < 0`?
##########
lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java:
##########
@@ -176,11 +179,17 @@ public final byte readByte(long pos) throws IOException {
public final short readShort(long pos) throws IOException {
long index = pos - bufferStart;
if (index < 0 || index >= buffer.limit() - 1) {
- bufferStart = pos;
+ // if we're moving backwards, then try and fill up the previous page
rather than
+ // starting again at the current pos, to avoid successive backwards
reads reloading
+ // the same data over and over again
+ bufferStart = index < 0 ? Math.min(pos, Math.max(0, bufferStart -
bufferSize)) : pos;
+ if (bufferStart + bufferSize - pos <= 1) {
Review Comment:
Nit: use `Short.BYTES` to make it clearier we're checking we can read a
whole short?
```suggestion
if (bufferStart + bufferSize - pos < Short.BYTES) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]