@@ -128,10 +128,8 @@ namespace {
128
128
SmallVector<DeclRefExpr *, 32 > BlockDeclRefs;
129
129
130
130
// Block related declarations.
131
- SmallVector<ValueDecl *, 8 > BlockByCopyDecls;
132
- llvm::SmallPtrSet<ValueDecl *, 8 > BlockByCopyDeclsPtrSet;
133
- SmallVector<ValueDecl *, 8 > BlockByRefDecls;
134
- llvm::SmallPtrSet<ValueDecl *, 8 > BlockByRefDeclsPtrSet;
131
+ llvm::SmallSetVector<ValueDecl *, 8 > BlockByCopyDecls;
132
+ llvm::SmallSetVector<ValueDecl *, 8 > BlockByRefDecls;
135
133
llvm::DenseMap<ValueDecl *, unsigned > BlockByRefDeclNo;
136
134
llvm::SmallPtrSet<ValueDecl *, 8 > ImportedBlockDecls;
137
135
llvm::SmallPtrSet<VarDecl *, 8 > ImportedLocalExternalDecls;
@@ -3357,7 +3355,7 @@ std::string RewriteObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i,
3357
3355
S += VD->getNameAsString ();
3358
3356
S += " , (void*)src->" ;
3359
3357
S += VD->getNameAsString ();
3360
- if (BlockByRefDeclsPtrSet. count (VD))
3358
+ if (BlockByRefDecls. contains (VD))
3361
3359
S += " , " + utostr (BLOCK_FIELD_IS_BYREF) + " /*BLOCK_FIELD_IS_BYREF*/);" ;
3362
3360
else if (VD->getType ()->isBlockPointerType ())
3363
3361
S += " , " + utostr (BLOCK_FIELD_IS_BLOCK) + " /*BLOCK_FIELD_IS_BLOCK*/);" ;
@@ -3374,7 +3372,7 @@ std::string RewriteObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i,
3374
3372
for (ValueDecl *VD : ImportedBlockDecls) {
3375
3373
S += " _Block_object_dispose((void*)src->" ;
3376
3374
S += VD->getNameAsString ();
3377
- if (BlockByRefDeclsPtrSet. count (VD))
3375
+ if (BlockByRefDecls. contains (VD))
3378
3376
S += " , " + utostr (BLOCK_FIELD_IS_BYREF) + " /*BLOCK_FIELD_IS_BYREF*/);" ;
3379
3377
else if (VD->getType ()->isBlockPointerType ())
3380
3378
S += " , " + utostr (BLOCK_FIELD_IS_BLOCK) + " /*BLOCK_FIELD_IS_BLOCK*/);" ;
@@ -3553,14 +3551,10 @@ void RewriteObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart,
3553
3551
DeclRefExpr *Exp = InnerDeclRefs[count++];
3554
3552
ValueDecl *VD = Exp->getDecl ();
3555
3553
BlockDeclRefs.push_back (Exp);
3556
- if (!VD->hasAttr <BlocksAttr>() && !BlockByCopyDeclsPtrSet.count (VD)) {
3557
- BlockByCopyDeclsPtrSet.insert (VD);
3558
- BlockByCopyDecls.push_back (VD);
3559
- }
3560
- if (VD->hasAttr <BlocksAttr>() && !BlockByRefDeclsPtrSet.count (VD)) {
3561
- BlockByRefDeclsPtrSet.insert (VD);
3562
- BlockByRefDecls.push_back (VD);
3563
- }
3554
+ if (VD->hasAttr <BlocksAttr>())
3555
+ BlockByRefDecls.insert (VD);
3556
+ else
3557
+ BlockByCopyDecls.insert (VD);
3564
3558
// imported objects in the inner blocks not used in the outer
3565
3559
// blocks must be copied/disposed in the outer block as well.
3566
3560
if (VD->hasAttr <BlocksAttr>() ||
@@ -3590,9 +3584,7 @@ void RewriteObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart,
3590
3584
3591
3585
BlockDeclRefs.clear ();
3592
3586
BlockByRefDecls.clear ();
3593
- BlockByRefDeclsPtrSet.clear ();
3594
3587
BlockByCopyDecls.clear ();
3595
- BlockByCopyDeclsPtrSet.clear ();
3596
3588
ImportedBlockDecls.clear ();
3597
3589
}
3598
3590
if (RewriteSC) {
@@ -4314,20 +4306,12 @@ void RewriteObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) {
4314
4306
if (BlockDeclRefs.size ()) {
4315
4307
// Unique all "by copy" declarations.
4316
4308
for (unsigned i = 0 ; i < BlockDeclRefs.size (); i++)
4317
- if (!BlockDeclRefs[i]->getDecl ()->hasAttr <BlocksAttr>()) {
4318
- if (!BlockByCopyDeclsPtrSet.count (BlockDeclRefs[i]->getDecl ())) {
4319
- BlockByCopyDeclsPtrSet.insert (BlockDeclRefs[i]->getDecl ());
4320
- BlockByCopyDecls.push_back (BlockDeclRefs[i]->getDecl ());
4321
- }
4322
- }
4309
+ if (!BlockDeclRefs[i]->getDecl ()->hasAttr <BlocksAttr>())
4310
+ BlockByCopyDecls.insert (BlockDeclRefs[i]->getDecl ());
4323
4311
// Unique all "by ref" declarations.
4324
4312
for (unsigned i = 0 ; i < BlockDeclRefs.size (); i++)
4325
- if (BlockDeclRefs[i]->getDecl ()->hasAttr <BlocksAttr>()) {
4326
- if (!BlockByRefDeclsPtrSet.count (BlockDeclRefs[i]->getDecl ())) {
4327
- BlockByRefDeclsPtrSet.insert (BlockDeclRefs[i]->getDecl ());
4328
- BlockByRefDecls.push_back (BlockDeclRefs[i]->getDecl ());
4329
- }
4330
- }
4313
+ if (BlockDeclRefs[i]->getDecl ()->hasAttr <BlocksAttr>())
4314
+ BlockByRefDecls.insert (BlockDeclRefs[i]->getDecl ());
4331
4315
// Find any imported blocks...they will need special attention.
4332
4316
for (unsigned i = 0 ; i < BlockDeclRefs.size (); i++)
4333
4317
if (BlockDeclRefs[i]->getDecl ()->hasAttr <BlocksAttr>() ||
@@ -4358,22 +4342,18 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,
4358
4342
for (unsigned i = 0 ; i < InnerBlockDeclRefs.size (); i++) {
4359
4343
DeclRefExpr *Exp = InnerBlockDeclRefs[i];
4360
4344
ValueDecl *VD = Exp->getDecl ();
4361
- if (!VD->hasAttr <BlocksAttr>() &&
4362
- BlockByCopyDeclsPtrSet.insert (VD).second ) {
4345
+ if (!VD->hasAttr <BlocksAttr>() && BlockByCopyDecls.insert (VD)) {
4363
4346
// We need to save the copied-in variables in nested
4364
4347
// blocks because it is needed at the end for some of the API
4365
4348
// generations. See SynthesizeBlockLiterals routine.
4366
4349
InnerDeclRefs.push_back (Exp);
4367
4350
countOfInnerDecls++;
4368
4351
BlockDeclRefs.push_back (Exp);
4369
- BlockByCopyDecls.push_back (VD);
4370
4352
}
4371
- if (VD->hasAttr <BlocksAttr>() &&
4372
- BlockByRefDeclsPtrSet.insert (VD).second ) {
4353
+ if (VD->hasAttr <BlocksAttr>() && BlockByRefDecls.insert (VD)) {
4373
4354
InnerDeclRefs.push_back (Exp);
4374
4355
countOfInnerDecls++;
4375
4356
BlockDeclRefs.push_back (Exp);
4376
- BlockByRefDecls.push_back (VD);
4377
4357
}
4378
4358
}
4379
4359
// Find any imported blocks...they will need special attention.
@@ -4534,9 +4514,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,
4534
4514
NewRep);
4535
4515
BlockDeclRefs.clear ();
4536
4516
BlockByRefDecls.clear ();
4537
- BlockByRefDeclsPtrSet.clear ();
4538
4517
BlockByCopyDecls.clear ();
4539
- BlockByCopyDeclsPtrSet.clear ();
4540
4518
ImportedBlockDecls.clear ();
4541
4519
return NewRep;
4542
4520
}
0 commit comments