[clang] Use *Set::insert_range (NFC) (#133357)
We can use *Set::insert_range to collapse:
for (auto Elem : Range)
Set.insert(E);
down to:
Set.insert_range(Range);
In some cases, we can further fold that into the set declaration.
diff --git a/clang/lib/Analysis/FlowSensitive/ASTOps.cpp b/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
index 9a46e79..431b1f2 100644
--- a/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
+++ b/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
@@ -64,8 +64,7 @@
!Type->isRecordType())
return;
- for (const FieldDecl *Field : Type->getAsRecordDecl()->fields())
- Fields.insert(Field);
+ Fields.insert_range(Type->getAsRecordDecl()->fields());
if (auto *CXXRecord = Type->getAsCXXRecordDecl())
for (const CXXBaseSpecifier &Base : CXXRecord->bases())
getFieldsFromClassHierarchy(Base.getType(), Fields);
@@ -260,15 +259,13 @@
bool VisitInitListExpr(InitListExpr *InitList) override {
if (InitList->getType()->isRecordType())
- for (const auto *FD : getFieldsForInitListExpr(InitList))
- Referenced.Fields.insert(FD);
+ Referenced.Fields.insert_range(getFieldsForInitListExpr(InitList));
return true;
}
bool VisitCXXParenListInitExpr(CXXParenListInitExpr *ParenInitList) override {
if (ParenInitList->getType()->isRecordType())
- for (const auto *FD : getFieldsForInitListExpr(ParenInitList))
- Referenced.Fields.insert(FD);
+ Referenced.Fields.insert_range(getFieldsForInitListExpr(ParenInitList));
return true;
}
diff --git a/clang/lib/Basic/TargetID.cpp b/clang/lib/Basic/TargetID.cpp
index b42d1f0..2a2f234 100644
--- a/clang/lib/Basic/TargetID.cpp
+++ b/clang/lib/Basic/TargetID.cpp
@@ -113,9 +113,8 @@
if (Processor.empty())
return std::nullopt;
- llvm::SmallSet<llvm::StringRef, 4> AllFeatures;
- for (auto &&F : getAllPossibleTargetIDFeatures(T, Processor))
- AllFeatures.insert(F);
+ llvm::SmallSet<llvm::StringRef, 4> AllFeatures(
+ llvm::from_range, getAllPossibleTargetIDFeatures(T, Processor));
for (auto &&F : *FeatureMap)
if (!AllFeatures.count(F.first()))
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 1ad34ae..a01fa157 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -703,8 +703,7 @@
for (auto I : Primary->Exports)
AllImports.insert(I.getPointer());
// Ones that we only import.
- for (Module *M : Primary->Imports)
- AllImports.insert(M);
+ AllImports.insert_range(Primary->Imports);
// Ones that we import in the global module fragment or the private module
// fragment.
for (Module *SubM : Primary->submodules()) {
@@ -714,8 +713,7 @@
assert(SubM->Exports.empty() &&
"The global mdoule fragments and the private module fragments are "
"not allowed to export import modules.");
- for (Module *M : SubM->Imports)
- AllImports.insert(M);
+ AllImports.insert_range(SubM->Imports);
}
SmallVector<llvm::Function *, 8> ModuleInits;
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 12a8894..5a4fa97 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14731,9 +14731,8 @@
/// (C++11 [class.mem] p18)
static bool isLayoutCompatibleUnion(const ASTContext &C, const RecordDecl *RD1,
const RecordDecl *RD2) {
- llvm::SmallPtrSet<const FieldDecl *, 8> UnmatchedFields;
- for (auto *Field2 : RD2->fields())
- UnmatchedFields.insert(Field2);
+ llvm::SmallPtrSet<const FieldDecl *, 8> UnmatchedFields(llvm::from_range,
+ RD2->fields());
for (auto *Field1 : RD1->fields()) {
auto I = UnmatchedFields.begin();
diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp
index 93a17e8..6db2c24 100644
--- a/clang/lib/Sema/SemaObjCProperty.cpp
+++ b/clang/lib/Sema/SemaObjCProperty.cpp
@@ -2075,10 +2075,9 @@
for (const auto *I : IMPDecl->property_impls())
PropImplMap.insert(I->getPropertyDecl());
- llvm::SmallPtrSet<const ObjCMethodDecl *, 8> InsMap;
// Collect property accessors implemented in current implementation.
- for (const auto *I : IMPDecl->methods())
- InsMap.insert(I);
+ llvm::SmallPtrSet<const ObjCMethodDecl *, 8> InsMap(llvm::from_range,
+ IMPDecl->methods());
ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(CDecl);
ObjCInterfaceDecl *PrimaryClass = nullptr;
@@ -2089,8 +2088,7 @@
// When reporting on missing setter/getters, do not report when
// setter/getter is implemented in category's primary class
// implementation.
- for (const auto *I : IMP->methods())
- InsMap.insert(I);
+ InsMap.insert_range(IMP->methods());
}
for (ObjCContainerDecl::PropertyMap::iterator
diff --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index f78b09a..720afea 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -1175,9 +1175,7 @@
// The TypeExtensions are space-separated in the .td file.
SmallVector<StringRef, 2> ExtVec;
TypeExt.split(ExtVec, " ");
- for (const auto Ext : ExtVec) {
- ExtSet.insert(Ext);
- }
+ ExtSet.insert_range(ExtVec);
}
}