[ADT/STLExtras.h] - Add llvm::is_sorted wrapper and update callers.
It can be used to avoid passing the begin and end of a range.
This makes the code shorter and it is consistent with another
wrappers we already have.
Differential revision: https://reviews.llvm.org/D78016
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index fb0c8b3..812fdc6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5352,7 +5352,7 @@
#ifndef NDEBUG
if (!MapProvenSorted) {
- assert(std::is_sorted(std::begin(IntrinsicMap), std::end(IntrinsicMap)));
+ assert(llvm::is_sorted(IntrinsicMap));
MapProvenSorted = true;
}
#endif
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 31ab797..1d0379a 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -5451,7 +5451,7 @@
// This isn't a stable sort, but our algorithm should handle it fine.
llvm::array_pod_sort(IvarsInfo.begin(), IvarsInfo.end());
} else {
- assert(std::is_sorted(IvarsInfo.begin(), IvarsInfo.end()));
+ assert(llvm::is_sorted(IvarsInfo));
}
assert(IvarsInfo.back().Offset < InstanceEnd);
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 4a5626d..9b65c79 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2049,8 +2049,7 @@
// enough as additional newlines might be added or removed across #include
// blocks. This we handle below by generating the updated #imclude blocks and
// comparing it to the original.
- if (Indices.size() == Includes.size() &&
- std::is_sorted(Indices.begin(), Indices.end()) &&
+ if (Indices.size() == Includes.size() && llvm::is_sorted(Indices) &&
Style.IncludeStyle.IncludeBlocks == tooling::IncludeStyle::IBS_Preserve)
return;
diff --git a/clang/lib/Format/SortJavaScriptImports.cpp b/clang/lib/Format/SortJavaScriptImports.cpp
index 5be243f..db2b65b 100644
--- a/clang/lib/Format/SortJavaScriptImports.cpp
+++ b/clang/lib/Format/SortJavaScriptImports.cpp
@@ -144,7 +144,7 @@
llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
return References[LHSI] < References[RHSI];
});
- bool ReferencesInOrder = std::is_sorted(Indices.begin(), Indices.end());
+ bool ReferencesInOrder = llvm::is_sorted(Indices);
std::string ReferencesText;
bool SymbolsInOrder = true;
diff --git a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
index e558354..62ac1ed 100644
--- a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -59,8 +59,7 @@
using CheckerOrPackage = typename CheckerOrPackageInfoList::value_type;
using CheckerOrPackageFullNameLT = FullNameLT<CheckerOrPackage>;
- assert(std::is_sorted(Collection.begin(), Collection.end(),
- CheckerOrPackageFullNameLT{}) &&
+ assert(llvm::is_sorted(Collection, CheckerOrPackageFullNameLT{}) &&
"In order to efficiently gather checkers/packages, this function "
"expects them to be already sorted!");
diff --git a/clang/lib/Tooling/Syntax/Tokens.cpp b/clang/lib/Tooling/Syntax/Tokens.cpp
index 1464d97..c6b9048 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -643,14 +643,13 @@
#ifndef NDEBUG
for (auto &pair : Result.Files) {
auto &mappings = pair.second.Mappings;
- assert(std::is_sorted(
- mappings.begin(), mappings.end(),
- [](const TokenBuffer::Mapping &M1, const TokenBuffer::Mapping &M2) {
- return M1.BeginSpelled < M2.BeginSpelled &&
- M1.EndSpelled < M2.EndSpelled &&
- M1.BeginExpanded < M2.BeginExpanded &&
- M1.EndExpanded < M2.EndExpanded;
- }));
+ assert(llvm::is_sorted(mappings, [](const TokenBuffer::Mapping &M1,
+ const TokenBuffer::Mapping &M2) {
+ return M1.BeginSpelled < M2.BeginSpelled &&
+ M1.EndSpelled < M2.EndSpelled &&
+ M1.BeginExpanded < M2.BeginExpanded &&
+ M1.EndExpanded < M2.EndExpanded;
+ }));
}
#endif