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
This commit is contained in:
Rafael Espindola 2015-07-13 22:01:02 +00:00
parent cc383db66a
commit 6d0b72637c

View File

@ -185,39 +185,20 @@ struct NMSymbol {
} }
static bool compareSymbolAddress(const NMSymbol &A, const NMSymbol &B) { static bool compareSymbolAddress(const NMSymbol &A, const NMSymbol &B) {
bool AUndefined = A.Sym.getFlags() & SymbolRef::SF_Undefined; bool ADefined = !(A.Sym.getFlags() & SymbolRef::SF_Undefined);
bool BUndefined = B.Sym.getFlags() & SymbolRef::SF_Undefined; bool BDefined = !(B.Sym.getFlags() & SymbolRef::SF_Undefined);
if (AUndefined && !BUndefined) return std::make_tuple(ADefined, A.Address, A.Name, A.Size) <
return true; std::make_tuple(BDefined, B.Address, B.Name, B.Size);
if (!AUndefined && BUndefined)
return false;
if (A.Address < B.Address)
return true;
if (A.Address == B.Address && A.Name < B.Name)
return true;
if (A.Address == B.Address && A.Name == B.Name && A.Size < B.Size)
return true;
return false;
} }
static bool compareSymbolSize(const NMSymbol &A, const NMSymbol &B) { static bool compareSymbolSize(const NMSymbol &A, const NMSymbol &B) {
if (A.Size < B.Size) return std::make_tuple(A.Size, A.Name, A.Address) <
return true; std::make_tuple(B.Size, B.Name, B.Address);
if (A.Size == B.Size && A.Name < B.Name)
return true;
if (A.Size == B.Size && A.Name == B.Name && A.Address < B.Address)
return true;
return false;
} }
static bool compareSymbolName(const NMSymbol &A, const NMSymbol &B) { static bool compareSymbolName(const NMSymbol &A, const NMSymbol &B) {
if (A.Name < B.Name) return std::make_tuple(A.Name, A.Size, A.Address) <
return true; std::make_tuple(B.Name, B.Size, B.Address);
if (A.Name == B.Name && A.Size < B.Size)
return true;
if (A.Name == B.Name && A.Size == B.Size && A.Address < B.Address)
return true;
return false;
} }
static char isSymbolList64Bit(SymbolicFile &Obj) { static char isSymbolList64Bit(SymbolicFile &Obj) {