Use getAndSet, getAndClear instead split operations. (#13507)

This commit is contained in:
zhouhui 2024-06-19 17:53:12 +08:00 committed by GitHub
parent 937c004eda
commit 057cbf3c86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 7 additions and 14 deletions

View File

@ -70,9 +70,8 @@ final class FreqProxTermsWriter extends TermsHash {
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);
}
}
}

View File

@ -97,9 +97,8 @@ class PendingDeletes {
+ 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;

View File

@ -53,8 +53,7 @@ final class PendingSoftDeletes extends PendingDeletes {
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
@ -135,16 +134,14 @@ final class PendingSoftDeletes extends PendingDeletes {
: 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--;
}
}

View File

@ -276,8 +276,7 @@ abstract class PointInSetIncludingScoreQuery extends Query implements Accountabl
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 {

View File

@ -281,9 +281,8 @@ class TermsIncludingScoreQuery extends Query implements Accountable {
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);
}
}
}