From a741b8c451a7f34487217f39a3e62061e82dc12c Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Mon, 3 Mar 2014 20:26:46 +0000 Subject: [PATCH] [C++11] Simplify compare operators with std::tie. No functionality change. llvm-svn: 202755 --- clang/include/clang/AST/VTableBuilder.h | 7 ++----- clang/include/clang/Basic/VersionTuple.h | 9 ++------- clang/include/clang/Edit/FileOffset.h | 12 ++++-------- .../StaticAnalyzer/Core/PathSensitive/APSIntType.h | 9 ++------- clang/lib/AST/VTableBuilder.cpp | 9 ++------- clang/lib/ASTMatchers/ASTMatchFinder.cpp | 7 ++----- clang/lib/CodeGen/CodeGenModule.h | 6 ++---- clang/lib/StaticAnalyzer/Core/BlockCounter.cpp | 3 +-- 8 files changed, 17 insertions(+), 45 deletions(-) diff --git a/clang/include/clang/AST/VTableBuilder.h b/clang/include/clang/AST/VTableBuilder.h index c51b884b83c6..8acee2eca215 100644 --- a/clang/include/clang/AST/VTableBuilder.h +++ b/clang/include/clang/AST/VTableBuilder.h @@ -471,11 +471,8 @@ public: assert(VBase != other.VBase); return VBTableIndex < other.VBTableIndex; } - if (VFPtrOffset != other.VFPtrOffset) - return VFPtrOffset < other.VFPtrOffset; - if (Index != other.Index) - return Index < other.Index; - return false; + return std::tie(VFPtrOffset, Index) < + std::tie(other.VFPtrOffset, other.Index); } }; diff --git a/clang/include/clang/Basic/VersionTuple.h b/clang/include/clang/Basic/VersionTuple.h index ff06a5c23d82..c054423befda 100644 --- a/clang/include/clang/Basic/VersionTuple.h +++ b/clang/include/clang/Basic/VersionTuple.h @@ -87,13 +87,8 @@ public: /// If not provided, minor and subminor version numbers are considered to be /// zero. friend bool operator<(const VersionTuple &X, const VersionTuple &Y) { - if (X.Major != Y.Major) - return X.Major < Y.Major; - - if (X.Minor != Y.Minor) - return X.Minor < Y.Minor; - - return X.Subminor < Y.Subminor; + return std::tie(X.Major, X.Minor, X.Subminor) < + std::tie(Y.Major, Y.Minor, Y.Subminor); } /// \brief Determine whether one version number follows another. diff --git a/clang/include/clang/Edit/FileOffset.h b/clang/include/clang/Edit/FileOffset.h index 675ad18fcd39..0c1e72b84e51 100644 --- a/clang/include/clang/Edit/FileOffset.h +++ b/clang/include/clang/Edit/FileOffset.h @@ -41,20 +41,16 @@ public: return !(LHS == RHS); } friend bool operator<(FileOffset LHS, FileOffset RHS) { - if (LHS.FID != RHS.FID) - return LHS.FID < RHS.FID; - return LHS.Offs < RHS.Offs; + return std::tie(LHS.FID, LHS.Offs) < std::tie(RHS.FID, RHS.Offs); } friend bool operator>(FileOffset LHS, FileOffset RHS) { - if (LHS.FID != RHS.FID) - return LHS.FID > RHS.FID; - return LHS.Offs > RHS.Offs; + return RHS < LHS; } friend bool operator>=(FileOffset LHS, FileOffset RHS) { - return LHS > RHS || LHS == RHS; + return !(LHS < RHS); } friend bool operator<=(FileOffset LHS, FileOffset RHS) { - return LHS < RHS || LHS == RHS; + return !(RHS < LHS); } }; diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h index 9502900f7e35..9356452f1459 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h @@ -97,13 +97,8 @@ public: /// Unsigned integers are considered to be better conversion types than /// signed integers of the same width. bool operator<(const APSIntType &Other) const { - if (BitWidth < Other.BitWidth) - return true; - if (BitWidth > Other.BitWidth) - return false; - if (!IsUnsigned && Other.IsUnsigned) - return true; - return false; + return std::tie(BitWidth, IsUnsigned) < + std::tie(Other.BitWidth, Other.IsUnsigned); } }; diff --git a/clang/lib/AST/VTableBuilder.cpp b/clang/lib/AST/VTableBuilder.cpp index 741be14da6d8..ce27fba524cb 100644 --- a/clang/lib/AST/VTableBuilder.cpp +++ b/clang/lib/AST/VTableBuilder.cpp @@ -2156,10 +2156,7 @@ void ItaniumVTableBuilder::dumpLayout(raw_ostream &Out) { std::sort(ThunksVector.begin(), ThunksVector.end(), [](const ThunkInfo &LHS, const ThunkInfo &RHS) { assert(LHS.Method == 0 && RHS.Method == 0); - - if (LHS.This != RHS.This) - return LHS.This < RHS.This; - return LHS.Return < RHS.Return; + return std::tie(LHS.This, LHS.Return) < std::tie(RHS.This, RHS.Return); }); Out << "Thunks for '" << MethodName << "' (" << ThunksVector.size(); @@ -3169,9 +3166,7 @@ void VFTableBuilder::dumpLayout(raw_ostream &Out) { [](const ThunkInfo &LHS, const ThunkInfo &RHS) { // Keep different thunks with the same adjustments in the order they // were put into the vector. - if (LHS.This != RHS.This) - return LHS.This < RHS.This; - return LHS.Return < RHS.Return; + return std::tie(LHS.This, LHS.Return) < std::tie(RHS.This, RHS.Return); }); Out << "Thunks for '" << MethodName << "' (" << ThunksVector.size(); diff --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp b/clang/lib/ASTMatchers/ASTMatchFinder.cpp index ac1bfa363d2b..b2911a3be256 100644 --- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp +++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp @@ -58,11 +58,8 @@ struct MatchKey { BoundNodesTreeBuilder BoundNodes; bool operator<(const MatchKey &Other) const { - if (MatcherID != Other.MatcherID) - return MatcherID < Other.MatcherID; - if (Node != Other.Node) - return Node < Other.Node; - return BoundNodes < Other.BoundNodes; + return std::tie(MatcherID, Node, BoundNodes) < + std::tie(Other.MatcherID, Other.Node, Other.BoundNodes); } }; diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 8feecea1fea5..9c20d8e605ea 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -99,10 +99,8 @@ namespace CodeGen { } bool operator<(const OrderGlobalInits &RHS) const { - if (priority < RHS.priority) - return true; - - return priority == RHS.priority && lex_order < RHS.lex_order; + return std::tie(priority, lex_order) < + std::tie(RHS.priority, RHS.lex_order); } }; diff --git a/clang/lib/StaticAnalyzer/Core/BlockCounter.cpp b/clang/lib/StaticAnalyzer/Core/BlockCounter.cpp index 74d761e1ecc1..c1ac03d5ab97 100644 --- a/clang/lib/StaticAnalyzer/Core/BlockCounter.cpp +++ b/clang/lib/StaticAnalyzer/Core/BlockCounter.cpp @@ -34,8 +34,7 @@ public: } bool operator<(const CountKey &RHS) const { - return (CallSite == RHS.CallSite) ? (BlockID < RHS.BlockID) - : (CallSite < RHS.CallSite); + return std::tie(CallSite, BlockID) < std::tie(RHS.CallSite, RHS.BlockID); } void Profile(llvm::FoldingSetNodeID &ID) const {