https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/132589
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently gained C++23-style insert_range. This patch replaces: Dest.insert(Src.begin(), Src.end()); with: Dest.insert_range(Src); >From 6d81053562d173a814e287c6dfee32cbb3d6c807 Mon Sep 17 00:00:00 2001 From: Kazu Hirata <k...@google.com> Date: Sat, 22 Mar 2025 08:16:13 -0700 Subject: [PATCH] [clang-tools-extra] Use *Set::insert_range (NFC) DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently gained C++23-style insert_range. This patch replaces: Dest.insert(Src.begin(), Src.end()); with: Dest.insert_range(Src); --- clang-tools-extra/clang-move/Move.cpp | 2 +- .../clang-tidy/bugprone/ExceptionEscapeCheck.cpp | 6 ++---- clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp | 4 ++-- .../clang-tidy/openmp/ExceptionEscapeCheck.cpp | 3 +-- clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp | 5 ++--- clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp | 4 ++-- clang-tools-extra/clangd/unittests/TestIndex.cpp | 2 +- 7 files changed, 11 insertions(+), 15 deletions(-) diff --git a/clang-tools-extra/clang-move/Move.cpp b/clang-tools-extra/clang-move/Move.cpp index ac16803b46783..17f597170f9f6 100644 --- a/clang-tools-extra/clang-move/Move.cpp +++ b/clang-tools-extra/clang-move/Move.cpp @@ -464,7 +464,7 @@ getUsedDecls(const HelperDeclRefGraph *RG, for (const auto *D : Decls) { auto Result = RG->getReachableNodes( HelperDeclRGBuilder::getOutmostClassOrFunDecl(D)); - Nodes.insert(Result.begin(), Result.end()); + Nodes.insert_range(Result); } llvm::DenseSet<const Decl *> Results; for (const auto *Node : Nodes) diff --git a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp index 3d1f63fcf33a5..7e9551532b72f 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp @@ -43,13 +43,11 @@ ExceptionEscapeCheck::ExceptionEscapeCheck(StringRef Name, IgnoredExceptionsVec; StringRef(RawFunctionsThatShouldNotThrow) .split(FunctionsThatShouldNotThrowVec, ",", -1, false); - FunctionsThatShouldNotThrow.insert(FunctionsThatShouldNotThrowVec.begin(), - FunctionsThatShouldNotThrowVec.end()); + FunctionsThatShouldNotThrow.insert_range(FunctionsThatShouldNotThrowVec); llvm::StringSet<> IgnoredExceptions; StringRef(RawIgnoredExceptions).split(IgnoredExceptionsVec, ",", -1, false); - IgnoredExceptions.insert(IgnoredExceptionsVec.begin(), - IgnoredExceptionsVec.end()); + IgnoredExceptions.insert_range(IgnoredExceptionsVec); Tracer.ignoreExceptions(std::move(IgnoredExceptions)); Tracer.ignoreBadAlloc(true); } diff --git a/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp b/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp index 2250bba4db669..47f3f96ed803b 100644 --- a/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp @@ -51,7 +51,7 @@ template <typename T, unsigned SmallSize> class ImmutableSmallSet { // We've decided that it isn't performant to keep using vector. // Let's migrate the data into Set. Set.reserve(Storage.size()); - Set.insert(Storage.begin(), Storage.end()); + Set.insert_range(Storage); } /// count - Return 1 if the element is in the set, 0 otherwise. @@ -97,7 +97,7 @@ template <typename T, unsigned SmallSize> class SmartSmallSetVector { const size_t NewMaxElts = 4 * Vector.size(); Vector.reserve(NewMaxElts); Set.reserve(NewMaxElts); - Set.insert(Vector.begin(), Vector.end()); + Set.insert_range(Vector); } /// count - Return 1 if the element is in the set, 0 otherwise. diff --git a/clang-tools-extra/clang-tidy/openmp/ExceptionEscapeCheck.cpp b/clang-tools-extra/clang-tidy/openmp/ExceptionEscapeCheck.cpp index b414fd3b4d1a3..64ca212473e10 100644 --- a/clang-tools-extra/clang-tidy/openmp/ExceptionEscapeCheck.cpp +++ b/clang-tools-extra/clang-tidy/openmp/ExceptionEscapeCheck.cpp @@ -30,8 +30,7 @@ ExceptionEscapeCheck::ExceptionEscapeCheck(StringRef Name, StringRef(RawIgnoredExceptions).split(IgnoredExceptionsVec, ",", -1, false); llvm::transform(IgnoredExceptionsVec, IgnoredExceptionsVec.begin(), [](StringRef S) { return S.trim(); }); - IgnoredExceptions.insert(IgnoredExceptionsVec.begin(), - IgnoredExceptionsVec.end()); + IgnoredExceptions.insert_range(IgnoredExceptionsVec); Tracer.ignoreExceptions(std::move(IgnoredExceptions)); Tracer.ignoreBadAlloc(true); } diff --git a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp index bc49fa856bafc..e28ee7d9c70f7 100644 --- a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp +++ b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp @@ -22,7 +22,7 @@ void ExceptionAnalyzer::ExceptionInfo::registerExceptions( if (Exceptions.empty()) return; Behaviour = State::Throwing; - ThrownExceptions.insert(Exceptions.begin(), Exceptions.end()); + ThrownExceptions.insert_range(Exceptions); } ExceptionAnalyzer::ExceptionInfo &ExceptionAnalyzer::ExceptionInfo::merge( @@ -39,8 +39,7 @@ ExceptionAnalyzer::ExceptionInfo &ExceptionAnalyzer::ExceptionInfo::merge( Behaviour = State::Unknown; ContainsUnknown = ContainsUnknown || Other.ContainsUnknown; - ThrownExceptions.insert(Other.ThrownExceptions.begin(), - Other.ThrownExceptions.end()); + ThrownExceptions.insert_range(Other.ThrownExceptions); return *this; } diff --git a/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp b/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp index f185808ae1544..d192749870d6f 100644 --- a/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp +++ b/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp @@ -202,7 +202,7 @@ class Lookup : public Command { } LookupRequest Request; - Request.IDs.insert(IDs.begin(), IDs.end()); + Request.IDs.insert_range(IDs); bool FoundSymbol = false; Index->lookup(Request, [&](const Symbol &Sym) { FoundSymbol = true; @@ -255,7 +255,7 @@ class Refs : public Command { } } RefsRequest RefRequest; - RefRequest.IDs.insert(IDs.begin(), IDs.end()); + RefRequest.IDs.insert_range(IDs); llvm::Regex RegexFilter(Filter); Index->refs(RefRequest, [&RegexFilter](const Ref &R) { auto U = URI::parse(R.Location.FileURI); diff --git a/clang-tools-extra/clangd/unittests/TestIndex.cpp b/clang-tools-extra/clangd/unittests/TestIndex.cpp index b13a5d32d1752..e9e02dd41f9e8 100644 --- a/clang-tools-extra/clangd/unittests/TestIndex.cpp +++ b/clang-tools-extra/clangd/unittests/TestIndex.cpp @@ -151,7 +151,7 @@ std::vector<std::string> match(const SymbolIndex &I, std::vector<std::string> lookup(const SymbolIndex &I, llvm::ArrayRef<SymbolID> IDs) { LookupRequest Req; - Req.IDs.insert(IDs.begin(), IDs.end()); + Req.IDs.insert_range(IDs); std::vector<std::string> Results; I.lookup(Req, [&](const Symbol &Sym) { Results.push_back(getQualifiedName(Sym)); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits