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 2010/05/04 20:08:28 UTC

svn commit: r940987 - in /lucene/java/branches/lucene_2_9: CHANGES.txt src/java/org/apache/lucene/store/IndexInput.java src/java/org/apache/lucene/store/IndexOutput.java

Author: mikemccand
Date: Tue May  4 18:08:28 2010
New Revision: 940987

URL: http://svn.apache.org/viewvc?rev=940987&view=rev
Log:
LUCENE-2422: don't reuse byte[] for String IO in IndexInput/Output

Modified:
    lucene/java/branches/lucene_2_9/CHANGES.txt
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/store/IndexInput.java
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/store/IndexOutput.java

Modified: lucene/java/branches/lucene_2_9/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/CHANGES.txt?rev=940987&r1=940986&r2=940987&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/CHANGES.txt (original)
+++ lucene/java/branches/lucene_2_9/CHANGES.txt Tue May  4 18:08:28 2010
@@ -48,6 +48,10 @@ Bug fixes
    (for example, text:foo^0) sorted incorrectly and produced
    invalid docids. (yonik)
 
+ * LUCENE-2422: Don't reuse byte[] in IndexInput/Output -- it gains
+   little performance, and ties up possibly large amounts of memory
+   for apps that index large docs.  (Ross Woolf via Mike McCandless)
+
 API Changes
 
  * LUCENE-2190: Added a new class CustomScoreProvider to function package

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/store/IndexInput.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/store/IndexInput.java?rev=940987&r1=940986&r2=940987&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/store/IndexInput.java (original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/store/IndexInput.java Tue May  4 18:08:28 2010
@@ -26,7 +26,6 @@ import java.util.HashMap;
  * @see Directory
  */
 public abstract class IndexInput implements Cloneable {
-  private byte[] bytes;                           // used by readString()
   private char[] chars;                           // used by readModifiedUTF8String()
   private boolean preUTF8Strings;                 // true if we are reading old (modified UTF8) string format
 
@@ -121,8 +120,7 @@ public abstract class IndexInput impleme
     if (preUTF8Strings)
       return readModifiedUTF8String();
     int length = readVInt();
-    if (bytes == null || length > bytes.length)
-      bytes = new byte[(int) (length*1.25)];
+    final byte[] bytes = new byte[length];
     readBytes(bytes, 0, length);
     return new String(bytes, 0, length, "UTF-8");
   }
@@ -222,7 +220,6 @@ public abstract class IndexInput impleme
       clone = (IndexInput)super.clone();
     } catch (CloneNotSupportedException e) {}
 
-    clone.bytes = null;
     clone.chars = null;
 
     return clone;

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/store/IndexOutput.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/store/IndexOutput.java?rev=940987&r1=940986&r2=940987&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/store/IndexOutput.java (original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/store/IndexOutput.java Tue May  4 18:08:28 2010
@@ -29,8 +29,6 @@ import org.apache.lucene.util.UnicodeUti
  */
 public abstract class IndexOutput {
 
-  private UnicodeUtil.UTF8Result utf8Result = new UnicodeUtil.UTF8Result();
-
   /** Writes a single byte.
    * @see IndexInput#readByte()
    */
@@ -101,6 +99,7 @@ public abstract class IndexOutput {
    * @see IndexInput#readString()
    */
   public void writeString(String s) throws IOException {
+    final UnicodeUtil.UTF8Result utf8Result = new UnicodeUtil.UTF8Result();
     UnicodeUtil.UTF16toUTF8(s, 0, s.length(), utf8Result);
     writeVInt(utf8Result.length);
     writeBytes(utf8Result.result, 0, utf8Result.length);