romseygeek commented on code in PR #12357:
URL: https://github.com/apache/lucene/pull/12357#discussion_r1224066078
##########
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:
I've rewritten this to extract a `maybeRefillBuffer()` method that should be
easier to read.
--
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]