uschindler commented on PR #12841:
URL: https://github.com/apache/lucene/pull/12841#issuecomment-1851098019

   Hi @easyice,
   I have a better idea. Lets keep the 2 different method, but do another trick:
   - The base class DataInput implements the public outer loop as a final 
implementation, subclasses won't override it: `public final void 
readGroupVInts(long[] dst, int limit) throws IOException`; this method does the 
outer loop and the tail readVInt(). There's nothing to optimize there anymore, 
so make that method final. The trick is now that this method calls inside the 
loop a `protected readGroupVInt()` method, where the default implementation of 
it is the one from the static helper class
   - Subclasses like MemorySegment/ByteBuffer would just override the protected 
`readGroupVInt()` and possible provide their own implementation.
   
   In short:
   - make the outer loop a final public method thats called from client code
   - make the previous private method to read a block protected and implement 
it in subclasses
   
   This allows subclasses to just optimize by overriding the protected method 
and from there call the static helper method with the lambda. MemorySegment 
would also wrap with try...catch.
   
   ```java 
   class DataInput.java:
   
     public final void readGroupVInts(long[] dst, int limit) throws IOException 
{
       int i;
       for (i = 0; i <= limit - 4; i += 4) {
         this.readGroupVInt(this, dst, i);
       }
       for (; i < limit; ++i) {
         dst[i] = readVInt();
       }
     }
   
   
     protected void readGroupVInt(long[] dst, int offset) throws IOException {
       GroupVIntUtil.readGroupVInt(this, dst, i);
     }
   
   
   class MemorySegmentindexInput:
   
     @Override
     protected void readGroupVInt(long[] dst, int offset) throws IOException {
       try {
           curPosition +=
               GroupVIntUtil.readGroupVInt(
                   this,
                   this.curSegment.byteSize() - curPosition,
                   p -> this.curSegment.get(LAYOUT_LE_INT, p),
                   curPosition,
                   dst,
                   i);
       } catch (NullPointerException | IllegalStateException e) {
         throw alreadyClosed(e);
       }
     }
   ```
   
   Do you get the idea?


-- 
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: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to