Skip to content

Commit 1f2d461

Browse files
authored
[NFC][MC][DecoderEmitter] Simplify loop to find the best filter (#156237)
We can just use `max_element` on the array of filters.
1 parent 865f956 commit 1f2d461

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,26 +1473,13 @@ FilterChooser::findBestFilter(ArrayRef<bitAttr_t> BitAttrs, bool AllowMixed,
14731473

14741474
// We have finished with the filter processings. Now it's time to choose
14751475
// the best performing filter.
1476-
unsigned BestIndex = 0;
1477-
bool AllUseless = true;
1478-
unsigned BestScore = 0;
1479-
1480-
for (const auto &[Idx, Filter] : enumerate(Filters)) {
1481-
unsigned Usefulness = Filter->usefulness();
1482-
1483-
if (Usefulness)
1484-
AllUseless = false;
1485-
1486-
if (Usefulness > BestScore) {
1487-
BestIndex = Idx;
1488-
BestScore = Usefulness;
1489-
}
1490-
}
1491-
1492-
if (AllUseless)
1476+
auto MaxIt = llvm::max_element(Filters, [](const std::unique_ptr<Filter> &A,
1477+
const std::unique_ptr<Filter> &B) {
1478+
return A->usefulness() < B->usefulness();
1479+
});
1480+
if (MaxIt == Filters.end() || (*MaxIt)->usefulness() == 0)
14931481
return nullptr;
1494-
1495-
return std::move(Filters[BestIndex]);
1482+
return std::move(*MaxIt);
14961483
}
14971484

14981485
std::unique_ptr<Filter> FilterChooser::findBestFilter() const {

0 commit comments

Comments
 (0)