-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[clang-tools-extra] Use *Set::insert_range (NFC) #132589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-tools-extra] Use *Set::insert_range (NFC) #132589
Conversation
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);
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang-tidy Author: Kazu Hirata (kazutakahirata) ChangesDenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently Dest.insert(Src.begin(), Src.end()); with: Dest.insert_range(Src); Full diff: https://github.com/llvm/llvm-project/pull/132589.diff 7 Files Affected:
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));
|
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);