Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 6d0b726

Browse files
committed
Use std::make_tuple to reduce code duplication.
Thanks to David Blaikie for the suggestion. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242074 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent cc383db commit 6d0b726

File tree

1 file changed

+8
-27
lines changed

1 file changed

+8
-27
lines changed

tools/llvm-nm/llvm-nm.cpp

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -185,39 +185,20 @@ struct NMSymbol {
185185
}
186186

187187
static bool compareSymbolAddress(const NMSymbol &A, const NMSymbol &B) {
188-
bool AUndefined = A.Sym.getFlags() & SymbolRef::SF_Undefined;
189-
bool BUndefined = B.Sym.getFlags() & SymbolRef::SF_Undefined;
190-
if (AUndefined && !BUndefined)
191-
return true;
192-
if (!AUndefined && BUndefined)
193-
return false;
194-
if (A.Address < B.Address)
195-
return true;
196-
if (A.Address == B.Address && A.Name < B.Name)
197-
return true;
198-
if (A.Address == B.Address && A.Name == B.Name && A.Size < B.Size)
199-
return true;
200-
return false;
188+
bool ADefined = !(A.Sym.getFlags() & SymbolRef::SF_Undefined);
189+
bool BDefined = !(B.Sym.getFlags() & SymbolRef::SF_Undefined);
190+
return std::make_tuple(ADefined, A.Address, A.Name, A.Size) <
191+
std::make_tuple(BDefined, B.Address, B.Name, B.Size);
201192
}
202193

203194
static bool compareSymbolSize(const NMSymbol &A, const NMSymbol &B) {
204-
if (A.Size < B.Size)
205-
return true;
206-
if (A.Size == B.Size && A.Name < B.Name)
207-
return true;
208-
if (A.Size == B.Size && A.Name == B.Name && A.Address < B.Address)
209-
return true;
210-
return false;
195+
return std::make_tuple(A.Size, A.Name, A.Address) <
196+
std::make_tuple(B.Size, B.Name, B.Address);
211197
}
212198

213199
static bool compareSymbolName(const NMSymbol &A, const NMSymbol &B) {
214-
if (A.Name < B.Name)
215-
return true;
216-
if (A.Name == B.Name && A.Size < B.Size)
217-
return true;
218-
if (A.Name == B.Name && A.Size == B.Size && A.Address < B.Address)
219-
return true;
220-
return false;
200+
return std::make_tuple(A.Name, A.Size, A.Address) <
201+
std::make_tuple(B.Name, B.Size, B.Address);
221202
}
222203

223204
static char isSymbolList64Bit(SymbolicFile &Obj) {

0 commit comments

Comments
 (0)