[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.
This commit is contained in:
@@ -64,8 +64,7 @@ static void getFieldsFromClassHierarchy(QualType Type, FieldSet &Fields) {
|
||||
!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 @@ public:
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -113,9 +113,8 @@ parseTargetID(const llvm::Triple &T, llvm::StringRef TargetID,
|
||||
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()))
|
||||
|
||||
@@ -703,8 +703,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
|
||||
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 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
|
||||
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;
|
||||
|
||||
@@ -14731,9 +14731,8 @@ static bool isLayoutCompatibleStruct(const ASTContext &C, const RecordDecl *RD1,
|
||||
/// (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();
|
||||
|
||||
@@ -2075,10 +2075,9 @@ void SemaObjC::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl,
|
||||
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 @@ void SemaObjC::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl,
|
||||
// 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
|
||||
|
||||
@@ -1175,9 +1175,7 @@ StringRef OpenCLBuiltinFileEmitterBase::emitTypeExtensionGuards(
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user