Apache Lucene open-source search software
Sorry for the last commit, this is the better solution. As the offset attribute was normally already added before in the indexing process, the addAttribute is at no cost. And the additional if-clause is prevented (I missed a second one in the previous commit). Now only payloads are conditional to attribute existence.
Uwe Schindlereeb96239db12
diff --git a/src/java/org/apache/lucene/index/TermVectorsTermsWriterPerField.java b/src/java/org/apache/lucene/index/TermVectorsTermsWriterPerField.javaindex c3d0b942416..0d7f0af12a2 100644--- a/src/java/org/apache/lucene/index/TermVectorsTermsWriterPerField.java+++ b/src/java/org/apache/lucene/index/TermVectorsTermsWriterPerField.java@@ -195,8 +195,8 @@ final class TermVectorsTermsWriterPerField extends TermsHashConsumerPerField {}void start(Fieldable f) {- if (doVectorOffsets && fieldState.attributeSource.hasAttribute(OffsetAttribute.class)) {- offsetAttribute = (OffsetAttribute) fieldState.attributeSource.getAttribute(OffsetAttribute.class);+ if (doVectorOffsets) {+ offsetAttribute = (OffsetAttribute) fieldState.attributeSource.addAttribute(OffsetAttribute.class);} else {offsetAttribute = null;}@@ -211,12 +211,8 @@ final class TermVectorsTermsWriterPerField extends TermsHashConsumerPerField {p.freq = 1;if (doVectorOffsets) {- int startOffset = fieldState.offset;- int endOffset = fieldState.offset;- if (offsetAttribute != null) {- startOffset += offsetAttribute.startOffset();- endOffset += offsetAttribute.endOffset();- }+ int startOffset = fieldState.offset + offsetAttribute.startOffset();;+ int endOffset = fieldState.offset + offsetAttribute.endOffset();termsHashPerField.writeVInt(1, startOffset);termsHashPerField.writeVInt(1, endOffset - startOffset);