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 11:46:19 UTC

[lucene-solr] branch branch_8x 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 branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


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

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

    LUCENE-9781: Speed up BytesStore reader setPosition (#2386)
---
 .../src/java/org/apache/lucene/util/fst/BytesStore.java    | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 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 02ff583..bdb1435 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
@@ -423,8 +423,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;
       }
@@ -482,10 +484,12 @@ 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();
+        assert getPosition() == pos : "pos=" + pos + " getPos()=" + getPosition();
       }
 
       @Override