-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Merged
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_set_use_insert_range_clang_tools_extra
Mar 23, 2025
Merged
[clang-tools-extra] Use *Set::insert_range (NFC) #132589
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_set_use_insert_range_clang_tools_extra
Mar 23, 2025
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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));
|
steakhal
approved these changes
Mar 23, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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);