Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp =================================================================== --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp @@ -549,8 +549,7 @@ DiagnosticsJSON.push_back(std::move(LSPDiag)); auto &FixItsForDiagnostic = LocalFixIts[Diag]; - std::copy(Fixes.begin(), Fixes.end(), - std::back_inserter(FixItsForDiagnostic)); + llvm::copy(Fixes, std::back_inserter(FixItsForDiagnostic)); }); } Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp =================================================================== --- clang-tools-extra/trunk/clangd/ClangdServer.cpp +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp @@ -361,17 +361,15 @@ // Lookup in a list of known extensions. auto SourceIter = - std::find_if(std::begin(SourceExtensions), std::end(SourceExtensions), - [&PathExt](PathRef SourceExt) { - return SourceExt.equals_lower(PathExt); - }); + llvm::find_if(SourceExtensions, [&PathExt](PathRef SourceExt) { + return SourceExt.equals_lower(PathExt); + }); bool IsSource = SourceIter != std::end(SourceExtensions); auto HeaderIter = - std::find_if(std::begin(HeaderExtensions), std::end(HeaderExtensions), - [&PathExt](PathRef HeaderExt) { - return HeaderExt.equals_lower(PathExt); - }); + llvm::find_if(HeaderExtensions, [&PathExt](PathRef HeaderExt) { + return HeaderExt.equals_lower(PathExt); + }); bool IsHeader = HeaderIter != std::end(HeaderExtensions); Index: clang-tools-extra/trunk/clangd/CodeComplete.cpp =================================================================== --- clang-tools-extra/trunk/clangd/CodeComplete.cpp +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp @@ -306,11 +306,10 @@ Completion.FixIts.push_back( toTextEdit(FixIt, ASTCtx.getSourceManager(), ASTCtx.getLangOpts())); } - std::sort(Completion.FixIts.begin(), Completion.FixIts.end(), - [](const TextEdit &X, const TextEdit &Y) { - return std::tie(X.range.start.line, X.range.start.character) < - std::tie(Y.range.start.line, Y.range.start.character); - }); + llvm::sort(Completion.FixIts, [](const TextEdit &X, const TextEdit &Y) { + return std::tie(X.range.start.line, X.range.start.character) < + std::tie(Y.range.start.line, Y.range.start.character); + }); Completion.Deprecated |= (C.SemaResult->Availability == CXAvailability_Deprecated); } @@ -861,8 +860,8 @@ IndexRequest.IDs.size(), FetchedDocs.size()); } - std::sort( - ScoredSignatures.begin(), ScoredSignatures.end(), + llvm::sort( + ScoredSignatures, [](const ScoredSignature &L, const ScoredSignature &R) { // Ordering follows: // - Less number of parameters is better. @@ -1164,13 +1163,12 @@ getRankedIncludes(const Symbol &Sym) { auto Includes = Sym.IncludeHeaders; // Sort in descending order by reference count and header length. - std::sort(Includes.begin(), Includes.end(), - [](const Symbol::IncludeHeaderWithReferences &LHS, - const Symbol::IncludeHeaderWithReferences &RHS) { - if (LHS.References == RHS.References) - return LHS.IncludeHeader.size() < RHS.IncludeHeader.size(); - return LHS.References > RHS.References; - }); + llvm::sort(Includes, [](const Symbol::IncludeHeaderWithReferences &LHS, + const Symbol::IncludeHeaderWithReferences &RHS) { + if (LHS.References == RHS.References) + return LHS.IncludeHeader.size() < RHS.IncludeHeader.size(); + return LHS.References > RHS.References; + }); llvm::SmallVector Headers; for (const auto &Include : Includes) Headers.push_back(Include.IncludeHeader); Index: clang-tools-extra/trunk/clangd/TUScheduler.cpp =================================================================== --- clang-tools-extra/trunk/clangd/TUScheduler.cpp +++ clang-tools-extra/trunk/clangd/TUScheduler.cpp @@ -128,8 +128,7 @@ using KVPair = std::pair>; std::vector::iterator findByKey(Key K) { - return std::find_if(LRU.begin(), LRU.end(), - [K](const KVPair &P) { return P.first == K; }); + return llvm::find_if(LRU, [K](const KVPair &P) { return P.first == K; }); } std::mutex Mut; Index: clang-tools-extra/trunk/clangd/XRefs.cpp =================================================================== --- clang-tools-extra/trunk/clangd/XRefs.cpp +++ clang-tools-extra/trunk/clangd/XRefs.cpp @@ -104,21 +104,19 @@ } // Sort results. Declarations being referenced explicitly come first. - std::sort(Result.begin(), Result.end(), - [](const DeclInfo &L, const DeclInfo &R) { - if (L.IsReferencedExplicitly != R.IsReferencedExplicitly) - return L.IsReferencedExplicitly > R.IsReferencedExplicitly; - return L.D->getBeginLoc() < R.D->getBeginLoc(); - }); + llvm::sort(Result, [](const DeclInfo &L, const DeclInfo &R) { + if (L.IsReferencedExplicitly != R.IsReferencedExplicitly) + return L.IsReferencedExplicitly > R.IsReferencedExplicitly; + return L.D->getBeginLoc() < R.D->getBeginLoc(); + }); return Result; } std::vector takeMacroInfos() { // Don't keep the same Macro info multiple times. - std::sort(MacroInfos.begin(), MacroInfos.end(), - [](const MacroDecl &Left, const MacroDecl &Right) { - return Left.Info < Right.Info; - }); + llvm::sort(MacroInfos, [](const MacroDecl &Left, const MacroDecl &Right) { + return Left.Info < Right.Info; + }); auto Last = std::unique(MacroInfos.begin(), MacroInfos.end(), [](const MacroDecl &Left, const MacroDecl &Right) { Index: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp =================================================================== --- clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp +++ clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp @@ -46,12 +46,11 @@ return SE->second; // Find the first header such that the extension is not '.inc', and isn't a // recognized non-header file - auto I = - std::find_if(Headers.begin(), Headers.end(), [](llvm::StringRef Include) { - // Skip .inc file whose including header file should - // be #included instead. - return !Include.endswith(".inc"); - }); + auto I = llvm::find_if(Headers, [](llvm::StringRef Include) { + // Skip .inc file whose including header file should + // be #included instead. + return !Include.endswith(".inc"); + }); if (I == Headers.end()) return Headers[0]; // Fallback to the declaring header. StringRef Header = *I; Index: clang-tools-extra/trunk/clangd/index/FileIndex.cpp =================================================================== --- clang-tools-extra/trunk/clangd/index/FileIndex.cpp +++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp @@ -128,8 +128,8 @@ for (auto &Sym : MergedRefs) { auto &SymRefs = Sym.second; // Sorting isn't required, but yields more stable results over rebuilds. - std::sort(SymRefs.begin(), SymRefs.end()); - std::copy(SymRefs.begin(), SymRefs.end(), back_inserter(RefsStorage)); + llvm::sort(SymRefs); + llvm::copy(SymRefs, back_inserter(RefsStorage)); AllRefs.try_emplace( Sym.first, ArrayRef(&RefsStorage[RefsStorage.size() - SymRefs.size()], Index: clang-tools-extra/trunk/clangd/index/Index.cpp =================================================================== --- clang-tools-extra/trunk/clangd/index/Index.cpp +++ clang-tools-extra/trunk/clangd/index/Index.cpp @@ -84,10 +84,8 @@ } SymbolSlab::const_iterator SymbolSlab::find(const SymbolID &ID) const { - auto It = std::lower_bound(Symbols.begin(), Symbols.end(), ID, - [](const Symbol &S, const SymbolID &I) { - return S.ID < I; - }); + auto It = llvm::lower_bound( + Symbols, ID, [](const Symbol &S, const SymbolID &I) { return S.ID < I; }); if (It != Symbols.end() && It->ID == ID) return It; return Symbols.end(); @@ -112,8 +110,8 @@ SymbolSlab SymbolSlab::Builder::build() && { Symbols = {Symbols.begin(), Symbols.end()}; // Force shrink-to-fit. // Sort symbols so the slab can binary search over them. - std::sort(Symbols.begin(), Symbols.end(), - [](const Symbol &L, const Symbol &R) { return L.ID < R.ID; }); + llvm::sort(Symbols, + [](const Symbol &L, const Symbol &R) { return L.ID < R.ID; }); // We may have unused strings from overwritten symbols. Build a new arena. BumpPtrAllocator NewArena; llvm::UniqueStringSaver Strings(NewArena); @@ -155,8 +153,8 @@ Result.reserve(Refs.size()); for (auto &Sym : Refs) { auto &SymRefs = Sym.second; - std::sort(SymRefs.begin(), SymRefs.end()); - // TODO: do we really need to dedup? + llvm::sort(SymRefs); + // FIXME: do we really need to dedup? SymRefs.erase(std::unique(SymRefs.begin(), SymRefs.end()), SymRefs.end()); auto *Array = Arena.Allocate(SymRefs.size()); Index: clang-tools-extra/trunk/clangd/index/Serialization.cpp =================================================================== --- clang-tools-extra/trunk/clangd/index/Serialization.cpp +++ clang-tools-extra/trunk/clangd/index/Serialization.cpp @@ -158,7 +158,7 @@ // Finalize the table and write it to OS. No more strings may be added. void finalize(raw_ostream &OS) { Sorted = {Unique.begin(), Unique.end()}; - std::sort(Sorted.begin(), Sorted.end()); + llvm::sort(Sorted); for (unsigned I = 0; I < Sorted.size(); ++I) Index.try_emplace({Sorted[I].data(), Sorted[I].size()}, I); Index: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp =================================================================== --- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp +++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp @@ -129,8 +129,7 @@ // will include OUTER_INNER and exclude some_enum_constant. // FIXME: the heuristic relies on naming style (i.e. no underscore in // user-defined names) and can be improved. - return (ND.getKind() != Decl::EnumConstant) || - std::any_of(Name.begin(), Name.end(), islower); + return (ND.getKind() != Decl::EnumConstant) || llvm::any_of(Name, islower); } // We only collect #include paths for symbols that are suitable for global code Index: clang-tools-extra/trunk/clangd/index/dex/Dex.cpp =================================================================== --- clang-tools-extra/trunk/clangd/index/dex/Dex.cpp +++ clang-tools-extra/trunk/clangd/index/dex/Dex.cpp @@ -123,8 +123,7 @@ // Symbols are sorted by symbol qualities so that items in the posting lists // are stored in the descending order of symbol quality. - std::sort(begin(ScoredSymbols), end(ScoredSymbols), - std::greater>()); + llvm::sort(ScoredSymbols, std::greater>()); // SymbolQuality was empty up until now. SymbolQuality.resize(Symbols.size()); Index: clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp =================================================================== --- clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp +++ clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp @@ -40,11 +40,10 @@ // highest element starting from the front. When child iterators in the // beginning have smaller estimated size, the sync() will have less restarts // and become more effective. - std::sort(begin(Children), end(Children), - [](const std::unique_ptr &LHS, - const std::unique_ptr &RHS) { - return LHS->estimateSize() < RHS->estimateSize(); - }); + llvm::sort(Children, [](const std::unique_ptr &LHS, + const std::unique_ptr &RHS) { + return LHS->estimateSize() < RHS->estimateSize(); + }); } bool reachedEnd() const override { return ReachedEnd; } Index: llvm/trunk/include/llvm/ADT/STLExtras.h =================================================================== --- llvm/trunk/include/llvm/ADT/STLExtras.h +++ llvm/trunk/include/llvm/ADT/STLExtras.h @@ -1139,6 +1139,12 @@ return std::lower_bound(adl_begin(Range), adl_end(Range), I); } +template +auto lower_bound(R &&Range, ForwardIt I, Compare C) + -> decltype(adl_begin(Range)) { + return std::lower_bound(adl_begin(Range), adl_end(Range), I, C); +} + /// Provide wrappers to std::upper_bound which take ranges instead of having to /// pass begin/end explicitly. template