You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2021/02/17 10:29:04 UTC

[lucene-solr] branch master updated: LUCENE-9781: Speed up BytesStore reader setPosition (#2386)

This is an automated email from the ASF dual-hosted git repository.

dweiss pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new effca16  LUCENE-9781: Speed up BytesStore reader setPosition (#2386)
effca16 is described below

commit effca165df4383926205b4c8fddda606ba725c4c
Author: Peter Gromov <pe...@jetbrains.com>
AuthorDate: Wed Feb 17 11:28:44 2021 +0100

    LUCENE-9781: Speed up BytesStore reader setPosition (#2386)
---
 .../core/src/java/org/apache/lucene/util/fst/BytesStore.java | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lucene/core/src/java/org/apache/lucene/util/fst/BytesStore.java b/lucene/core/src/java/org/apache/lucene/util/fst/BytesStore.java
index a370d0f..2278c27 100644
--- a/lucene/core/src/java/org/apache/lucene/util/fst/BytesStore.java
+++ b/lucene/core/src/java/org/apache/lucene/util/fst/BytesStore.java
@@ -425,8 +425,10 @@ class BytesStore extends DataOutput implements Accountable {
       @Override
       public void setPosition(long pos) {
         int bufferIndex = (int) (pos >> blockBits);
-        nextBuffer = bufferIndex + 1;
-        current = blocks.get(bufferIndex);
+        if (nextBuffer != bufferIndex + 1) {
+          nextBuffer = bufferIndex + 1;
+          current = blocks.get(bufferIndex);
+        }
         nextRead = (int) (pos & blockMask);
         assert getPosition() == pos;
       }
@@ -484,8 +486,10 @@ class BytesStore extends DataOutput implements Accountable {
         // bytes[0] ... but I would expect bytes[-1] (ie,
         // EOF)...?
         int bufferIndex = (int) (pos >> blockBits);
-        nextBuffer = bufferIndex - 1;
-        current = blocks.get(bufferIndex);
+        if (nextBuffer != bufferIndex - 1) {
+          nextBuffer = bufferIndex - 1;
+          current = blocks.get(bufferIndex);
+        }
         nextRead = (int) (pos & blockMask);
         assert getPosition() == pos : "pos=" + pos + " getPos()=" + getPosition();
       }