Only check liveDocs is null one time.

This commit is contained in:
zhouhui 2024-06-20 10:19:50 +08:00
parent 036275df66
commit aaa0e3ef10
1 changed files with 10 additions and 4 deletions

View File

@ -59,6 +59,12 @@ final class FreqProxTermsWriter extends TermsHash {
FrozenBufferedUpdates.TermDocsIterator iterator =
new FrozenBufferedUpdates.TermDocsIterator(fields, true);
// Since we have already applied delete-by-docID, liveDocs maybe not null.
if (state.liveDocs == null) {
state.liveDocs = new FixedBitSet(state.segmentInfo.maxDoc());
state.liveDocs.set(0, state.segmentInfo.maxDoc());
}
segDeletes.forEachOrdered(
(term, docId) -> {
DocIdSetIterator postings = iterator.nextTerm(term.field(), term.bytes());
@ -66,16 +72,16 @@ final class FreqProxTermsWriter extends TermsHash {
assert docId < PostingsEnum.NO_MORE_DOCS;
int doc;
while ((doc = postings.nextDoc()) < docId) {
if (state.liveDocs == null) {
state.liveDocs = new FixedBitSet(state.segmentInfo.maxDoc());
state.liveDocs.set(0, state.segmentInfo.maxDoc());
}
if (state.liveDocs.getAndClear(doc)) {
state.delCountOnFlush++;
}
}
}
});
// Set to null, if there is no delete.
if (state.delCountOnFlush == 0) {
state.liveDocs = null;
}
}
}