Skip to content

Commit c1d21f4

Browse files
[lld] Use std::tie to implement comparison operators (NFC) (#143726)
std::tie facilitates lexicographical comparisons through std::tuple's built-in operator< and operator>.
1 parent e266d6a commit c1d21f4

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

lld/ELF/SyntheticSections.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,11 +1939,8 @@ bool AndroidPackedRelocationSection<ELFT>::updateAllocSize(Ctx &ctx) {
19391939
// For Rela, we also want to sort by r_addend when r_info is the same. This
19401940
// enables us to group by r_addend as well.
19411941
llvm::sort(nonRelatives, [](const Elf_Rela &a, const Elf_Rela &b) {
1942-
if (a.r_info != b.r_info)
1943-
return a.r_info < b.r_info;
1944-
if (a.r_addend != b.r_addend)
1945-
return a.r_addend < b.r_addend;
1946-
return a.r_offset < b.r_offset;
1942+
return std::tie(a.r_info, a.r_addend, a.r_offset) <
1943+
std::tie(b.r_info, b.r_addend, b.r_offset);
19471944
});
19481945

19491946
// Group relocations with the same r_info. Note that each group emits a group

lld/MachO/UnwindInfoSection.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,9 @@ void UnwindInfoSectionImpl::finalize() {
535535
llvm::sort(commonEncodings,
536536
[](const std::pair<compact_unwind_encoding_t, size_t> &a,
537537
const std::pair<compact_unwind_encoding_t, size_t> &b) {
538-
if (a.second == b.second)
539-
// When frequencies match, secondarily sort on encoding
540-
// to maintain parity with validate-unwind-info.py
541-
return a.first > b.first;
542-
return a.second > b.second;
538+
// When frequencies match, secondarily sort on encoding
539+
// to maintain parity with validate-unwind-info.py
540+
return std::tie(a.second, a.first) > std::tie(b.second, b.first);
543541
});
544542

545543
// Truncate the vector to 127 elements.

0 commit comments

Comments
 (0)