Skip to content

Commit

Permalink
Use getAndSet, getAndClear instead split operations. (apache#13507)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsop-479 authored Jun 19, 2024
1 parent 937c004 commit 057cbf3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ private void applyDeletes(SegmentWriteState state, Fields fields) throws IOExcep
state.liveDocs = new FixedBitSet(state.segmentInfo.maxDoc());
state.liveDocs.set(0, state.segmentInfo.maxDoc());
}
if (state.liveDocs.get(doc)) {
if (state.liveDocs.getAndClear(doc)) {
state.delCountOnFlush++;
state.liveDocs.clear(doc);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ boolean delete(int docID) throws IOException {
+ info.info.name
+ " maxDoc="
+ info.info.maxDoc();
final boolean didDelete = mutableBits.get(docID);
final boolean didDelete = mutableBits.getAndClear(docID);
if (didDelete) {
mutableBits.clear(docID);
pendingDeleteCount++;
}
return didDelete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ boolean delete(int docID) throws IOException {
FixedBitSet mutableBits = getMutableBits();
// hardDeletes
if (hardDeletes.delete(docID)) {
if (mutableBits.get(docID)) { // delete it here too!
mutableBits.clear(docID);
if (mutableBits.getAndClear(docID)) { // delete it here too!
assert hardDeletes.delete(docID) == false;
} else {
// if it was deleted subtract the delCount
Expand Down Expand Up @@ -135,16 +134,14 @@ static int applySoftDeletes(DocIdSetIterator iterator, FixedBitSet bits) throws
: null;
while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
if (hasValue == null || hasValue.hasValue()) {
if (bits.get(docID)) { // doc is live - clear it
bits.clear(docID);
if (bits.getAndClear(docID)) { // doc is live - clear it
newDeletes++;
// now that we know we deleted it and we fully control the hard deletes we can do correct
// accounting
// below.
}
} else {
if (bits.get(docID) == false) {
bits.set(docID);
if (bits.getAndSet(docID) == false) {
newDeletes--;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ public void visit(int docID, byte[] packedValue) {
if (cmp == 0) {
// Query point equals index point, so collect and return
if (multipleValuesPerDocument) {
if (result.get(docID) == false) {
result.set(docID);
if (result.getAndSet(docID) == false) {
scores[docID] = nextScore;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,8 @@ protected void fillDocsAndScores(FixedBitSet matchingDocs, TermsEnum termsEnum)
matchingDocs.set(doc);
}*/
// But this behaves the same as MVInnerScorer and only then the tests will pass:
if (!matchingDocs.get(doc)) {
if (!matchingDocs.getAndSet(doc)) {
scores[doc] = score;
matchingDocs.set(doc);
}
}
}
Expand Down

0 comments on commit 057cbf3

Please sign in to comment.