Simplify the loop.
@@ -120,31 +120,21 @@ TargetWeightedResult::getResult(ReverseMappingRefs reverseMappingRefs, const Rev
{
TargetWeightedResult targetResult;
fef::TermFieldMatchData matchData;
- auto targetItr = target_search_context.createIterator(&matchData, true);
+ auto it = target_search_context.createIterator(&matchData, true);
uint32_t docIdLimit = reverseMappingRefs.size();
if (docIdLimit > committedDocIdLimit) {
docIdLimit = committedDocIdLimit;
}
- uint32_t lid = 1;
- targetItr->initRange(1, docIdLimit);
- while (lid < docIdLimit) {
- if (targetItr->seek(lid)) {
+ it->initRange(1, docIdLimit);
+ for (uint32_t lid = it->seekFirst(1); !it->isAtEnd(); lid = it->seekNext(lid+1)) {
EntryRef revMapIdx = reverseMappingRefs[lid];
- if (revMapIdx.valid()) {
+ if (__builtin_expect(revMapIdx.valid(), true)) {
uint32_t size = reverseMapping.frozenSize(revMapIdx);
targetResult.sizeSum += size;
- targetItr->unpack(lid);
+ it->doUnpack(lid);
int32_t weight = matchData.getWeight();
targetResult.weightedRefs.emplace_back(revMapIdx, weight);
}
- ++lid;
- } else {
- ++lid;
- uint32_t nextLid = targetItr->getDocId();
- if (nextLid > lid) {
- lid = nextLid;
- }
- }
}
return targetResult;
}
