@@ -128,10 +128,8 @@ namespace {
128128 SmallVector<DeclRefExpr *, 32 > BlockDeclRefs;
129129
130130 // 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;
135133 llvm::DenseMap<ValueDecl *, unsigned > BlockByRefDeclNo;
136134 llvm::SmallPtrSet<ValueDecl *, 8 > ImportedBlockDecls;
137135 llvm::SmallPtrSet<VarDecl *, 8 > ImportedLocalExternalDecls;
@@ -3357,7 +3355,7 @@ std::string RewriteObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i,
33573355 S += VD->getNameAsString ();
33583356 S += " , (void*)src->" ;
33593357 S += VD->getNameAsString ();
3360- if (BlockByRefDeclsPtrSet. count (VD))
3358+ if (BlockByRefDecls. contains (VD))
33613359 S += " , " + utostr (BLOCK_FIELD_IS_BYREF) + " /*BLOCK_FIELD_IS_BYREF*/);" ;
33623360 else if (VD->getType ()->isBlockPointerType ())
33633361 S += " , " + utostr (BLOCK_FIELD_IS_BLOCK) + " /*BLOCK_FIELD_IS_BLOCK*/);" ;
@@ -3374,7 +3372,7 @@ std::string RewriteObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i,
33743372 for (ValueDecl *VD : ImportedBlockDecls) {
33753373 S += " _Block_object_dispose((void*)src->" ;
33763374 S += VD->getNameAsString ();
3377- if (BlockByRefDeclsPtrSet. count (VD))
3375+ if (BlockByRefDecls. contains (VD))
33783376 S += " , " + utostr (BLOCK_FIELD_IS_BYREF) + " /*BLOCK_FIELD_IS_BYREF*/);" ;
33793377 else if (VD->getType ()->isBlockPointerType ())
33803378 S += " , " + utostr (BLOCK_FIELD_IS_BLOCK) + " /*BLOCK_FIELD_IS_BLOCK*/);" ;
@@ -3553,14 +3551,10 @@ void RewriteObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart,
35533551 DeclRefExpr *Exp = InnerDeclRefs[count++];
35543552 ValueDecl *VD = Exp->getDecl ();
35553553 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);
35643558 // imported objects in the inner blocks not used in the outer
35653559 // blocks must be copied/disposed in the outer block as well.
35663560 if (VD->hasAttr <BlocksAttr>() ||
@@ -3590,9 +3584,7 @@ void RewriteObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart,
35903584
35913585 BlockDeclRefs.clear ();
35923586 BlockByRefDecls.clear ();
3593- BlockByRefDeclsPtrSet.clear ();
35943587 BlockByCopyDecls.clear ();
3595- BlockByCopyDeclsPtrSet.clear ();
35963588 ImportedBlockDecls.clear ();
35973589 }
35983590 if (RewriteSC) {
@@ -4314,20 +4306,12 @@ void RewriteObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) {
43144306 if (BlockDeclRefs.size ()) {
43154307 // Unique all "by copy" declarations.
43164308 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 ());
43234311 // Unique all "by ref" declarations.
43244312 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 ());
43314315 // Find any imported blocks...they will need special attention.
43324316 for (unsigned i = 0 ; i < BlockDeclRefs.size (); i++)
43334317 if (BlockDeclRefs[i]->getDecl ()->hasAttr <BlocksAttr>() ||
@@ -4358,22 +4342,18 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,
43584342 for (unsigned i = 0 ; i < InnerBlockDeclRefs.size (); i++) {
43594343 DeclRefExpr *Exp = InnerBlockDeclRefs[i];
43604344 ValueDecl *VD = Exp->getDecl ();
4361- if (!VD->hasAttr <BlocksAttr>() &&
4362- BlockByCopyDeclsPtrSet.insert (VD).second ) {
4345+ if (!VD->hasAttr <BlocksAttr>() && BlockByCopyDecls.insert (VD)) {
43634346 // We need to save the copied-in variables in nested
43644347 // blocks because it is needed at the end for some of the API
43654348 // generations. See SynthesizeBlockLiterals routine.
43664349 InnerDeclRefs.push_back (Exp);
43674350 countOfInnerDecls++;
43684351 BlockDeclRefs.push_back (Exp);
4369- BlockByCopyDecls.push_back (VD);
43704352 }
4371- if (VD->hasAttr <BlocksAttr>() &&
4372- BlockByRefDeclsPtrSet.insert (VD).second ) {
4353+ if (VD->hasAttr <BlocksAttr>() && BlockByRefDecls.insert (VD)) {
43734354 InnerDeclRefs.push_back (Exp);
43744355 countOfInnerDecls++;
43754356 BlockDeclRefs.push_back (Exp);
4376- BlockByRefDecls.push_back (VD);
43774357 }
43784358 }
43794359 // Find any imported blocks...they will need special attention.
@@ -4534,9 +4514,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,
45344514 NewRep);
45354515 BlockDeclRefs.clear ();
45364516 BlockByRefDecls.clear ();
4537- BlockByRefDeclsPtrSet.clear ();
45384517 BlockByCopyDecls.clear ();
4539- BlockByCopyDeclsPtrSet.clear ();
45404518 ImportedBlockDecls.clear ();
45414519 return NewRep;
45424520}
0 commit comments