You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by mi...@apache.org on 2007/07/04 19:00:23 UTC

svn commit: r553269 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/index/CompoundFileReader.java src/java/org/apache/lucene/store/BufferedIndexInput.java src/java/org/apache/lucene/store/IndexInput.java

Author: mikemccand
Date: Wed Jul  4 10:00:22 2007
New Revision: 553269

URL: http://svn.apache.org/viewvc?view=rev&rev=553269
Log:
LUCENE-892: don't do extra buffer-to-buffer copies in CompoundFileReader.CSIndexInput

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/CompoundFileReader.java
    lucene/java/trunk/src/java/org/apache/lucene/store/BufferedIndexInput.java
    lucene/java/trunk/src/java/org/apache/lucene/store/IndexInput.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?view=diff&rev=553269&r1=553268&r2=553269
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Wed Jul  4 10:00:22 2007
@@ -39,6 +39,9 @@
     postings per unique term and is directly flushed into a single
     segment.  (Mike McCandless)
  
+ 3. LUCENE-892: Fixed extra "buffer to buffer copy" that sometimes
+    takes place when using compound files.  (Mike McCandless)
+
 Documentation
 
 Build

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/CompoundFileReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/CompoundFileReader.java?view=diff&rev=553269&r1=553268&r2=553269
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/CompoundFileReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/CompoundFileReader.java Wed Jul  4 10:00:22 2007
@@ -237,7 +237,7 @@
               if(start + len > length)
                 throw new IOException("read past EOF");
               base.seek(fileOffset + start);
-              base.readBytes(b, offset, len);
+              base.readBytes(b, offset, len, false);
             }
         }
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/BufferedIndexInput.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/BufferedIndexInput.java?view=diff&rev=553269&r1=553268&r2=553269
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/BufferedIndexInput.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/BufferedIndexInput.java Wed Jul  4 10:00:22 2007
@@ -84,8 +84,13 @@
   }
 
   public void readBytes(byte[] b, int offset, int len) throws IOException {
+    readBytes(b, offset, len, true);
+  }
+
+  public void readBytes(byte[] b, int offset, int len, boolean useBuffer) throws IOException {
+
     if(len <= (bufferLength-bufferPosition)){
-      // the buffer contains enough data to satistfy this request
+      // the buffer contains enough data to satisfy this request
       if(len>0) // to allow b to be null if len is 0...
         System.arraycopy(buffer, bufferPosition, b, offset, len);
       bufferPosition+=len;
@@ -99,8 +104,9 @@
         bufferPosition += available;
       }
       // and now, read the remaining 'len' bytes:
-      if(len<bufferSize){
-        // If the amount left to read is small enough, do it in the usual
+      if (useBuffer && len<bufferSize){
+        // If the amount left to read is small enough, and
+        // we are allowed to use our buffer, do it in the usual
         // buffered way: fill the buffer and copy from it:
         refill();
         if(bufferLength<len){
@@ -112,10 +118,13 @@
           bufferPosition=len;
         }
       } else {
-        // The amount left to read is larger than the buffer - there's no
-        // performance reason not to read it all at once. Note that unlike
-        // the previous code of this function, there is no need to do a seek
-        // here, because there's no need to reread what we had in the buffer.
+        // The amount left to read is larger than the buffer
+        // or we've been asked to not use our buffer -
+        // there's no performance reason not to read it all
+        // at once. Note that unlike the previous code of
+        // this function, there is no need to do a seek
+        // here, because there's no need to reread what we
+        // had in the buffer.
         long after = bufferStart+bufferPosition+len;
         if(after > length())
           throw new IOException("read past EOF");

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/IndexInput.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/IndexInput.java?view=diff&rev=553269&r1=553268&r2=553269
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/IndexInput.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/IndexInput.java Wed Jul  4 10:00:22 2007
@@ -40,6 +40,25 @@
   public abstract void readBytes(byte[] b, int offset, int len)
     throws IOException;
 
+  /** Reads a specified number of bytes into an array at the
+   * specified offset with control over whether the read
+   * should be buffered (callers who have their own buffer
+   * should pass in "false" for useBuffer).  Currently only
+   * {@link BufferedIndexInput} respects this parameter.
+   * @param b the array to read bytes into
+   * @param offset the offset in the array to start storing bytes
+   * @param len the number of bytes to read
+   * @param useBuffer set to false if the caller will handle
+   * buffering.
+   * @see IndexOutput#writeBytes(byte[],int)
+   */
+  public void readBytes(byte[] b, int offset, int len, boolean useBuffer)
+    throws IOException
+  {
+    // Default to ignoring useBuffer entirely
+    readBytes(b, offset, len);
+  }
+
   /** Reads four bytes and returns an int.
    * @see IndexOutput#writeInt(int)
    */