LUCENE-2422: don't reuse byte[]/char[] for String IO in IndexInput/Output

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@940994 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2010-05-04 18:38:18 +00:00
parent 27502aa045
commit 49631091d6
3 changed files with 7 additions and 13 deletions

View File

@ -365,6 +365,10 @@ Bug fixes
* LUCENE-2074: Reduce buffer size of lexer back to default on reset.
(Ruben Laguna, Shai Erera via Uwe Schindler)
* 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)
New features
* LUCENE-2128: Parallelized fetching document frequencies during weight

View File

@ -29,8 +29,6 @@ import org.apache.lucene.util.RamUsageEstimator;
* data types.
*/
public abstract class DataInput 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
/** Reads and returns a single byte.
@ -131,18 +129,14 @@ public abstract class DataInput implements Cloneable {
if (preUTF8Strings)
return readModifiedUTF8String();
int length = readVInt();
if (bytes == null || length > bytes.length) {
bytes = new byte[ArrayUtil.oversize(length, 1)];
}
final byte[] bytes = new byte[length];
readBytes(bytes, 0, length);
return new String(bytes, 0, length, "UTF-8");
}
private String readModifiedUTF8String() throws IOException {
int length = readVInt();
if (chars == null || length > chars.length) {
chars = new char[ArrayUtil.oversize(length, RamUsageEstimator.NUM_BYTES_CHAR)];
}
final char[] chars = new char[length];
readChars(chars, 0, length);
return new String(chars, 0, length);
}
@ -219,9 +213,6 @@ public abstract class DataInput implements Cloneable {
clone = (DataInput)super.clone();
} catch (CloneNotSupportedException e) {}
clone.bytes = null;
clone.chars = null;
return clone;
}

View File

@ -29,8 +29,6 @@ import org.apache.lucene.util.UnicodeUtil;
*/
public abstract class DataOutput {
private BytesRef utf8Result = new BytesRef(10);
/** Writes a single byte.
* @see IndexInput#readByte()
*/
@ -101,6 +99,7 @@ public abstract class DataOutput {
* @see DataInput#readString()
*/
public void writeString(String s) throws IOException {
final BytesRef utf8Result = new BytesRef(10);
UnicodeUtil.UTF16toUTF8(s, 0, s.length(), utf8Result);
writeVInt(utf8Result.length);
writeBytes(utf8Result.bytes, 0, utf8Result.length);