diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2022-07-23 15:14:14 +0200 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2022-07-23 15:19:05 +0200 |
commit | aba43035bdf89c08409f0efccaf5408165abed9e (patch) | |
tree | ae91c3b453964fe779d5dc8562b90507f59abe86 /clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp | |
parent | e82880e6b8cd2f01ee18e99c4c7b6ec71b764e13 (diff) | |
download | llvm-aba43035bdf89c08409f0efccaf5408165abed9e.zip llvm-aba43035bdf89c08409f0efccaf5408165abed9e.tar.gz llvm-aba43035bdf89c08409f0efccaf5408165abed9e.tar.bz2 |
Use llvm::sort instead of std::sort where possible
llvm::sort is beneficial even when we use the iterator-based overload,
since it can optionally shuffle the elements (to detect
non-determinism). However llvm::sort is not usable everywhere, for
example, in compiler-rt.
Reviewed By: nhaehnle
Differential Revision: https://reviews.llvm.org/D130406
Diffstat (limited to 'clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp index 948bf16..f701bd1 100644 --- a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp @@ -10,6 +10,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" +#include "llvm/ADT/STLExtras.h" #include <map> @@ -125,20 +126,20 @@ void IncludeOrderPPCallbacks::EndOfMainFile() { // Sort the includes. We first sort by priority, then lexicographically. for (unsigned BI = 0, BE = Blocks.size() - 1; BI != BE; ++BI) - std::sort(IncludeIndices.begin() + Blocks[BI], - IncludeIndices.begin() + Blocks[BI + 1], - [&FileDirectives](unsigned LHSI, unsigned RHSI) { - IncludeDirective &LHS = FileDirectives[LHSI]; - IncludeDirective &RHS = FileDirectives[RHSI]; - - int PriorityLHS = - getPriority(LHS.Filename, LHS.IsAngled, LHS.IsMainModule); - int PriorityRHS = - getPriority(RHS.Filename, RHS.IsAngled, RHS.IsMainModule); - - return std::tie(PriorityLHS, LHS.Filename) < - std::tie(PriorityRHS, RHS.Filename); - }); + llvm::sort(IncludeIndices.begin() + Blocks[BI], + IncludeIndices.begin() + Blocks[BI + 1], + [&FileDirectives](unsigned LHSI, unsigned RHSI) { + IncludeDirective &LHS = FileDirectives[LHSI]; + IncludeDirective &RHS = FileDirectives[RHSI]; + + int PriorityLHS = getPriority(LHS.Filename, LHS.IsAngled, + LHS.IsMainModule); + int PriorityRHS = getPriority(RHS.Filename, RHS.IsAngled, + RHS.IsMainModule); + + return std::tie(PriorityLHS, LHS.Filename) < + std::tie(PriorityRHS, RHS.Filename); + }); // Emit a warning for each block and fixits for all changes within that // block. |