[lld] Use std::tie to implement comparison operators (NFC) (#143726)
std::tie facilitates lexicographical comparisons through std::tuple's built-in operator< and operator>.
This commit is contained in:
@@ -1939,11 +1939,8 @@ bool AndroidPackedRelocationSection<ELFT>::updateAllocSize(Ctx &ctx) {
|
|||||||
// For Rela, we also want to sort by r_addend when r_info is the same. This
|
// For Rela, we also want to sort by r_addend when r_info is the same. This
|
||||||
// enables us to group by r_addend as well.
|
// enables us to group by r_addend as well.
|
||||||
llvm::sort(nonRelatives, [](const Elf_Rela &a, const Elf_Rela &b) {
|
llvm::sort(nonRelatives, [](const Elf_Rela &a, const Elf_Rela &b) {
|
||||||
if (a.r_info != b.r_info)
|
return std::tie(a.r_info, a.r_addend, a.r_offset) <
|
||||||
return a.r_info < b.r_info;
|
std::tie(b.r_info, b.r_addend, b.r_offset);
|
||||||
if (a.r_addend != b.r_addend)
|
|
||||||
return a.r_addend < b.r_addend;
|
|
||||||
return a.r_offset < b.r_offset;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Group relocations with the same r_info. Note that each group emits a group
|
// Group relocations with the same r_info. Note that each group emits a group
|
||||||
|
|||||||
@@ -535,11 +535,9 @@ void UnwindInfoSectionImpl::finalize() {
|
|||||||
llvm::sort(commonEncodings,
|
llvm::sort(commonEncodings,
|
||||||
[](const std::pair<compact_unwind_encoding_t, size_t> &a,
|
[](const std::pair<compact_unwind_encoding_t, size_t> &a,
|
||||||
const std::pair<compact_unwind_encoding_t, size_t> &b) {
|
const std::pair<compact_unwind_encoding_t, size_t> &b) {
|
||||||
if (a.second == b.second)
|
// When frequencies match, secondarily sort on encoding
|
||||||
// When frequencies match, secondarily sort on encoding
|
// to maintain parity with validate-unwind-info.py
|
||||||
// to maintain parity with validate-unwind-info.py
|
return std::tie(a.second, a.first) > std::tie(b.second, b.first);
|
||||||
return a.first > b.first;
|
|
||||||
return a.second > b.second;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Truncate the vector to 127 elements.
|
// Truncate the vector to 127 elements.
|
||||||
|
|||||||
Reference in New Issue
Block a user