lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bmes...@apache.org
Subject svn commit: r170226 - /lucene/java/trunk/src/java/org/apache/lucene/index/TermVectorsReader.java
Date Sun, 15 May 2005 15:04:40 GMT
Author: bmesser
Date: Sun May 15 08:04:39 2005
New Revision: 170226

URL: http://svn.apache.org/viewcvs?rev=170226&view=rev
Log:
optimized buffer handling and runtime optimization.
The initial buffer size is set to 10 characters, so it doesn't have to be increased that often.
If the buffer has to grow, just copy the identical pattern and not the whole string.

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/TermVectorsReader.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/TermVectorsReader.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/index/TermVectorsReader.java?rev=170226&r1=170225&r2=170226&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/TermVectorsReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/TermVectorsReader.java Sun May 15 08:04:39
2005
@@ -241,22 +241,24 @@
     int start = 0;
     int deltaLength = 0;
     int totalLength = 0;
-    char [] buffer = {};
-    String previousString = "";
+    char [] buffer = new char[10];    // init the buffer with a length of 10 character
+    char[] previousBuffer = {};
     
     for (int i = 0; i < numTerms; i++) {
       start = tvf.readVInt();
       deltaLength = tvf.readVInt();
       totalLength = start + deltaLength;
-      if (buffer.length < totalLength)
-      {
+      if (buffer.length < totalLength) {  // increase buffer
+        buffer = null;    // give a hint to garbage collector
         buffer = new char[totalLength];
-        for (int j = 0; j < previousString.length(); j++)  // copy contents
-          buffer[j] = previousString.charAt(j);
+        
+        if (start > 0)  // just copy if necessary
+          System.arraycopy(previousBuffer, 0, buffer, 0, start);
       }
+      
       tvf.readChars(buffer, start, deltaLength);
       terms[i] = new String(buffer, 0, totalLength);
-      previousString = terms[i];
+      previousBuffer = buffer;
       int freq = tvf.readVInt();
       termFreqs[i] = freq;
       



Mime
View raw message