Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-1217: use Field.isBinary instead of 'instanceof'

Michael McCandlessa6258c76fdae
diff --git a/CHANGES.txt b/CHANGES.txt
index 05ce53cb86c..63efd4408cb 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -133,6 +133,10 @@ Optimizations
SegmentTermEnum is null for every call of scanTo().
(Christian Kohlschuetter via Michael Busch)
+ 4. LUCENE-1217: Internal to Field.java, use isBinary instead of
+ runtime type checking for possible speedup of binaryValue().
+ (Eks Dev via Mike McCandless)
+
Documentation
Build
diff --git a/src/java/org/apache/lucene/document/Field.java b/src/java/org/apache/lucene/document/Field.java
index 5e49d1acbe6..9d308424e81 100644
--- a/src/java/org/apache/lucene/document/Field.java
+++ b/src/java/org/apache/lucene/document/Field.java
@@ -148,7 +148,7 @@ public final class Field extends AbstractField implements Fieldable, Serializabl
/** The value of the field in Binary, or null. If null, the Reader value,
* String value, or TokenStream value is used. Exactly one of stringValue(),
* readerValue(), binaryValue(), and tokenStreamValue() must be set. */
- public byte[] binaryValue() { return fieldsData instanceof byte[] ? (byte[])fieldsData : null; }
+ public byte[] binaryValue() { return isBinary ? (byte[])fieldsData : null; }
/** The value of the field as a TokesStream, or null. If null, the Reader value,
* String value, or binary value is used. Exactly one of stringValue(),
diff --git a/src/java/org/apache/lucene/index/FieldsReader.java b/src/java/org/apache/lucene/index/FieldsReader.java
index e0855d7adf6..d34758f4f9f 100644
--- a/src/java/org/apache/lucene/index/FieldsReader.java
+++ b/src/java/org/apache/lucene/index/FieldsReader.java
@@ -416,7 +416,7 @@ final class FieldsReader {
if (fieldsData == null) {
final byte[] b = new byte[toRead];
IndexInput localFieldsStream = getFieldStream();
- //Throw this IO Exception since IndexREader.document does so anyway, so probably not that big of a change for people
+ //Throw this IO Exception since IndexReader.document does so anyway, so probably not that big of a change for people
//since they are already handling this exception when getting the document
try {
localFieldsStream.seek(pointer);
@@ -426,11 +426,12 @@ final class FieldsReader {
} else {
fieldsData = b;
}
+ isBinary = true;
} catch (IOException e) {
throw new FieldReaderException(e);
}
}
- return fieldsData instanceof byte[] ? (byte[]) fieldsData : null;
+ return isBinary ? (byte[]) fieldsData : null;
}
/** The value of the field as a Reader, or null. If null, the String value,