Skip to content

Commit cb80b26

Browse files
[clang] Use *Set::insert_range (NFC) (llvm#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.
1 parent a1bb750 commit cb80b26

File tree

6 files changed

+13
-24
lines changed

6 files changed

+13
-24
lines changed

clang/lib/Analysis/FlowSensitive/ASTOps.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ static void getFieldsFromClassHierarchy(QualType Type, FieldSet &Fields) {
6464
!Type->isRecordType())
6565
return;
6666

67-
for (const FieldDecl *Field : Type->getAsRecordDecl()->fields())
68-
Fields.insert(Field);
67+
Fields.insert_range(Type->getAsRecordDecl()->fields());
6968
if (auto *CXXRecord = Type->getAsCXXRecordDecl())
7069
for (const CXXBaseSpecifier &Base : CXXRecord->bases())
7170
getFieldsFromClassHierarchy(Base.getType(), Fields);
@@ -260,15 +259,13 @@ class ReferencedDeclsVisitor : public AnalysisASTVisitor {
260259

261260
bool VisitInitListExpr(InitListExpr *InitList) override {
262261
if (InitList->getType()->isRecordType())
263-
for (const auto *FD : getFieldsForInitListExpr(InitList))
264-
Referenced.Fields.insert(FD);
262+
Referenced.Fields.insert_range(getFieldsForInitListExpr(InitList));
265263
return true;
266264
}
267265

268266
bool VisitCXXParenListInitExpr(CXXParenListInitExpr *ParenInitList) override {
269267
if (ParenInitList->getType()->isRecordType())
270-
for (const auto *FD : getFieldsForInitListExpr(ParenInitList))
271-
Referenced.Fields.insert(FD);
268+
Referenced.Fields.insert_range(getFieldsForInitListExpr(ParenInitList));
272269
return true;
273270
}
274271

clang/lib/Basic/TargetID.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ parseTargetID(const llvm::Triple &T, llvm::StringRef TargetID,
113113
if (Processor.empty())
114114
return std::nullopt;
115115

116-
llvm::SmallSet<llvm::StringRef, 4> AllFeatures;
117-
for (auto &&F : getAllPossibleTargetIDFeatures(T, Processor))
118-
AllFeatures.insert(F);
116+
llvm::SmallSet<llvm::StringRef, 4> AllFeatures(
117+
llvm::from_range, getAllPossibleTargetIDFeatures(T, Processor));
119118

120119
for (auto &&F : *FeatureMap)
121120
if (!AllFeatures.count(F.first()))

clang/lib/CodeGen/CGDeclCXX.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
703703
for (auto I : Primary->Exports)
704704
AllImports.insert(I.getPointer());
705705
// Ones that we only import.
706-
for (Module *M : Primary->Imports)
707-
AllImports.insert(M);
706+
AllImports.insert_range(Primary->Imports);
708707
// Ones that we import in the global module fragment or the private module
709708
// fragment.
710709
for (Module *SubM : Primary->submodules()) {
@@ -714,8 +713,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
714713
assert(SubM->Exports.empty() &&
715714
"The global mdoule fragments and the private module fragments are "
716715
"not allowed to export import modules.");
717-
for (Module *M : SubM->Imports)
718-
AllImports.insert(M);
716+
AllImports.insert_range(SubM->Imports);
719717
}
720718

721719
SmallVector<llvm::Function *, 8> ModuleInits;

clang/lib/Sema/SemaChecking.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -14731,9 +14731,8 @@ static bool isLayoutCompatibleStruct(const ASTContext &C, const RecordDecl *RD1,
1473114731
/// (C++11 [class.mem] p18)
1473214732
static bool isLayoutCompatibleUnion(const ASTContext &C, const RecordDecl *RD1,
1473314733
const RecordDecl *RD2) {
14734-
llvm::SmallPtrSet<const FieldDecl *, 8> UnmatchedFields;
14735-
for (auto *Field2 : RD2->fields())
14736-
UnmatchedFields.insert(Field2);
14734+
llvm::SmallPtrSet<const FieldDecl *, 8> UnmatchedFields(llvm::from_range,
14735+
RD2->fields());
1473714736

1473814737
for (auto *Field1 : RD1->fields()) {
1473914738
auto I = UnmatchedFields.begin();

clang/lib/Sema/SemaObjCProperty.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -2075,10 +2075,9 @@ void SemaObjC::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl,
20752075
for (const auto *I : IMPDecl->property_impls())
20762076
PropImplMap.insert(I->getPropertyDecl());
20772077

2078-
llvm::SmallPtrSet<const ObjCMethodDecl *, 8> InsMap;
20792078
// Collect property accessors implemented in current implementation.
2080-
for (const auto *I : IMPDecl->methods())
2081-
InsMap.insert(I);
2079+
llvm::SmallPtrSet<const ObjCMethodDecl *, 8> InsMap(llvm::from_range,
2080+
IMPDecl->methods());
20822081

20832082
ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(CDecl);
20842083
ObjCInterfaceDecl *PrimaryClass = nullptr;
@@ -2089,8 +2088,7 @@ void SemaObjC::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl,
20892088
// When reporting on missing setter/getters, do not report when
20902089
// setter/getter is implemented in category's primary class
20912090
// implementation.
2092-
for (const auto *I : IMP->methods())
2093-
InsMap.insert(I);
2091+
InsMap.insert_range(IMP->methods());
20942092
}
20952093

20962094
for (ObjCContainerDecl::PropertyMap::iterator

clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -1175,9 +1175,7 @@ StringRef OpenCLBuiltinFileEmitterBase::emitTypeExtensionGuards(
11751175
// The TypeExtensions are space-separated in the .td file.
11761176
SmallVector<StringRef, 2> ExtVec;
11771177
TypeExt.split(ExtVec, " ");
1178-
for (const auto Ext : ExtVec) {
1179-
ExtSet.insert(Ext);
1180-
}
1178+
ExtSet.insert_range(ExtVec);
11811179
}
11821180
}
11831181

0 commit comments

Comments
 (0)