uschindler commented on issue #15730:
URL: https://github.com/apache/lucene/issues/15730#issuecomment-4313925359
Possibly like that:
```java
@Override
public short readShort(long pos) throws IOException {
final int si = (int) (pos >> chunkSizePower);
try {
return segments[si].get(LAYOUT_LE_SHORT, pos & chunkSizeMask);
} catch (IndexOutOfBoundsException _) {
positionalWithSeek(this::readShort);
} catch (NullPointerException | IllegalStateException e) {
throw alreadyClosed(e);
}
}
private <R> R positionalReadWithSeek(long pos, int si, Supplier<T> read) {
// Need to save the file pointer (see RandomAccessInput), so save and
restore curSegment state.
final int savedSegmentIndex = curSegmentIndex;
final MemorySegment savedSegment = curSegment;
final long savedPosition = curPosition;
try {
setPos(pos, si);
return read.get();
} finally {
this.curSegmentIndex = savedSegmentIndex;
this.curSegment = savedSegment;
this.curPosition = savedPosition;
}
}
```
Don't complain about the lambda overhead or the primitive wrappers, but as
it happens seldom it's no issue.
I would agree to that code for the positional reads, I just don't want to
have the duplicated code.
--
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]