mirror of https://github.com/apache/lucene.git
LUCENE-7419: Don't lookup PositionIncrementAttribute every time in TokenStream.end()
This commit is contained in:
parent
2c7d86bc4d
commit
f8536ce726
|
@ -91,6 +91,9 @@ Bug Fixes
|
||||||
* SOLR-9413: Fix analysis/kuromoji's CSVUtil.quoteEscape logic, add TestCSVUtil test.
|
* SOLR-9413: Fix analysis/kuromoji's CSVUtil.quoteEscape logic, add TestCSVUtil test.
|
||||||
(AppChecker, Christine Poerschke)
|
(AppChecker, Christine Poerschke)
|
||||||
|
|
||||||
|
* LUCENE-7419: Fix performance bug with TokenStream.end(), where it would lookup
|
||||||
|
PositionIncrementAttribute every time. (Mike McCandless, Robert Muir)
|
||||||
|
|
||||||
Improvements
|
Improvements
|
||||||
|
|
||||||
* LUCENE-7323: Compound file writing now verifies the incoming
|
* LUCENE-7323: Compound file writing now verifies the incoming
|
||||||
|
|
|
@ -22,7 +22,6 @@ import java.io.Closeable;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.tokenattributes.PackedTokenAttributeImpl;
|
import org.apache.lucene.analysis.tokenattributes.PackedTokenAttributeImpl;
|
||||||
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
|
|
||||||
import org.apache.lucene.document.Document;
|
import org.apache.lucene.document.Document;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.index.IndexWriter;
|
import org.apache.lucene.index.IndexWriter;
|
||||||
|
@ -176,11 +175,7 @@ public abstract class TokenStream extends AttributeSource implements Closeable {
|
||||||
* @throws IOException If an I/O error occurs
|
* @throws IOException If an I/O error occurs
|
||||||
*/
|
*/
|
||||||
public void end() throws IOException {
|
public void end() throws IOException {
|
||||||
clearAttributes(); // LUCENE-3849: don't consume dirty atts
|
endAttributes(); // LUCENE-3849: don't consume dirty atts
|
||||||
PositionIncrementAttribute posIncAtt = getAttribute(PositionIncrementAttribute.class);
|
|
||||||
if (posIncAtt != null) {
|
|
||||||
posIncAtt.setPositionIncrement(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -138,6 +138,17 @@ public class PackedTokenAttributeImpl extends CharTermAttributeImpl
|
||||||
startOffset = endOffset = 0;
|
startOffset = endOffset = 0;
|
||||||
type = DEFAULT_TYPE;
|
type = DEFAULT_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Resets the attributes at end
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void end() {
|
||||||
|
super.end();
|
||||||
|
positionIncrement = 0;
|
||||||
|
positionLength = 1;
|
||||||
|
startOffset = endOffset = 0;
|
||||||
|
type = DEFAULT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PackedTokenAttributeImpl clone() {
|
public PackedTokenAttributeImpl clone() {
|
||||||
|
|
|
@ -46,6 +46,11 @@ public class PositionIncrementAttributeImpl extends AttributeImpl implements Pos
|
||||||
this.positionIncrement = 1;
|
this.positionIncrement = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void end() {
|
||||||
|
this.positionIncrement = 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (other == this) {
|
if (other == this) {
|
||||||
|
|
|
@ -32,6 +32,17 @@ public abstract class AttributeImpl implements Cloneable, Attribute {
|
||||||
*/
|
*/
|
||||||
public abstract void clear();
|
public abstract void clear();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the values in this AttributeImpl and resets it to its value
|
||||||
|
* at the end of the field. If this implementation implements more than one Attribute interface
|
||||||
|
* it clears all.
|
||||||
|
* <p>
|
||||||
|
* The default implementation simply calls {@link #clear()}
|
||||||
|
*/
|
||||||
|
public void end() {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns the current attribute values as a string in the following format
|
* This method returns the current attribute values as a string in the following format
|
||||||
* by calling the {@link #reflectWith(AttributeReflector)} method:
|
* by calling the {@link #reflectWith(AttributeReflector)} method:
|
||||||
|
|
|
@ -270,6 +270,16 @@ public class AttributeSource {
|
||||||
state.attribute.clear();
|
state.attribute.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets all Attributes in this AttributeSource by calling
|
||||||
|
* {@link AttributeImpl#end()} on each Attribute implementation.
|
||||||
|
*/
|
||||||
|
public final void endAttributes() {
|
||||||
|
for (State state = getCurrentState(); state != null; state = state.next) {
|
||||||
|
state.attribute.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all attributes and their implementations from this AttributeSource.
|
* Removes all attributes and their implementations from this AttributeSource.
|
||||||
|
|
Loading…
Reference in New Issue