Use {DenseSet,SetVector,SmallPtrSet}::contains (NFC)
authorKazu Hirata <kazu@google.com>
Sun, 31 Oct 2021 02:00:19 +0000 (19:00 -0700)
committerKazu Hirata <kazu@google.com>
Sun, 31 Oct 2021 02:00:19 +0000 (19:00 -0700)
14 files changed:
clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
clang/include/clang/Basic/TargetInfo.h
clang/include/clang/Sema/Scope.h
clang/lib/AST/ASTImporterLookupTable.cpp
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/AST/VTableBuilder.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/Sema/SemaDeclObjC.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
llvm/tools/llvm-objcopy/COFF/Object.cpp

index 7f851f0ba023797ba0d9a3683d2ea9abccf882db..c98a1ab7104fb74843ab2d2ee882c15620dd1ec3 100644 (file)
@@ -123,7 +123,7 @@ void ForwardDeclarationNamespaceCheck::onEndOfTranslationUnit() {
       if (CurDecl->hasDefinition() || CurDecl->isReferenced()) {
         continue; // Skip forward declarations that are used/referenced.
       }
-      if (FriendTypes.count(CurDecl->getTypeForDecl()) != 0) {
+      if (FriendTypes.contains(CurDecl->getTypeForDecl())) {
         continue; // Skip forward declarations referenced as friend.
       }
       if (CurDecl->getLocation().isMacroID() ||
index 0c220e865ff48655511bd0a017d613e2123c4ef4..aa9a0ca80458dc43d057671d2c2746c2b521a375 100644 (file)
@@ -209,7 +209,7 @@ computeInsertions(const CXXConstructorDecl::init_const_range &Inits,
       // Add all fields between current field up until the next initializer.
       for (; Decl != std::end(OrderedDecls) && *Decl != InitDecl; ++Decl) {
         if (const auto *D = dyn_cast<T>(*Decl)) {
-          if (DeclsToInit.count(D) > 0)
+          if (DeclsToInit.contains(D))
             Insertions.back().Initializers.emplace_back(getName(D));
         }
       }
@@ -221,7 +221,7 @@ computeInsertions(const CXXConstructorDecl::init_const_range &Inits,
   // Add remaining decls that require initialization.
   for (; Decl != std::end(OrderedDecls); ++Decl) {
     if (const auto *D = dyn_cast<T>(*Decl)) {
-      if (DeclsToInit.count(D) > 0)
+      if (DeclsToInit.contains(D))
         Insertions.back().Initializers.emplace_back(getName(D));
     }
   }
index ca96ab67090ccf2b905d1081e416482ba544e991..04dff8dfefe06e97dd64c2037a0a8ca9cbd884a8 100644 (file)
@@ -172,7 +172,7 @@ void UnusedUsingDeclsCheck::removeFromFoundDecls(const Decl *D) {
   //
   // FIXME: Use a more efficient way to find a matching context.
   for (auto &Context : Contexts) {
-    if (Context.UsingTargetDecls.count(D->getCanonicalDecl()) > 0)
+    if (Context.UsingTargetDecls.contains(D->getCanonicalDecl()))
       Context.IsUsed = true;
   }
 }
index 9d467e54a98d887eb5f3d84623a09bfd927812f4..1fcd1b76af852ddee0416d96beea531096f8bb17 100644 (file)
@@ -303,7 +303,7 @@ void InconsistentDeclarationParameterNameCheck::check(
   const auto *OriginalDeclaration =
       Result.Nodes.getNodeAs<FunctionDecl>("functionDecl");
 
-  if (VisitedDeclarations.count(OriginalDeclaration) > 0)
+  if (VisitedDeclarations.contains(OriginalDeclaration))
     return; // Avoid multiple warnings.
 
   const FunctionDecl *ParameterSourceDeclaration =
index 98a4f4a4343f8bea6f8d193093f05b0992730dc7..77a510462a65e122fbb4c27881b366bccd28df3f 100644 (file)
@@ -1013,8 +1013,7 @@ public:
     }
     bool isValidAsmImmediate(const llvm::APInt &Value) const {
       if (!ImmSet.empty())
-        return Value.isSignedIntN(32) &&
-               ImmSet.count(Value.getZExtValue()) != 0;
+        return Value.isSignedIntN(32) && ImmSet.contains(Value.getZExtValue());
       return !ImmRange.isConstrained ||
              (Value.sge(ImmRange.Min) && Value.sle(ImmRange.Max));
     }
index b499ba1e7c2afd94f4c48b416e44695fad3333fd..872951a0829b451498b0d64eea5541ef9f306f3e 100644 (file)
@@ -337,7 +337,7 @@ public:
 
   /// isDeclScope - Return true if this is the scope that the specified decl is
   /// declared in.
-  bool isDeclScope(const Decl *D) const { return DeclsInScope.count(D) != 0; }
+  bool isDeclScope(const Decl *D) const { return DeclsInScope.contains(D); }
 
   /// Get the entity corresponding to this scope.
   DeclContext *getEntity() const {
index b78cc0c053f60ff65a94191563064fb1135f505b..bf772c20d32ee227ef94604224a2bb1449ee1f18 100644 (file)
@@ -145,7 +145,7 @@ ASTImporterLookupTable::lookup(DeclContext *DC, DeclarationName Name) const {
 }
 
 bool ASTImporterLookupTable::contains(DeclContext *DC, NamedDecl *ND) const {
-  return 0 < lookup(DC, ND->getDeclName()).count(ND);
+  return lookup(DC, ND->getDeclName()).contains(ND);
 }
 
 void ASTImporterLookupTable::dump(DeclContext *DC) const {
index 35c0e92038a748465e88bd3474797c1786bd07de..3e39ec1c718d1ff1a5406ae5e8e25d516d1cff4f 100644 (file)
@@ -3091,7 +3091,7 @@ void MicrosoftRecordLayoutBuilder::layoutVirtualBases(const CXXRecordDecl *RD) {
   for (const CXXBaseSpecifier &VBase : RD->vbases()) {
     const CXXRecordDecl *BaseDecl = VBase.getType()->getAsCXXRecordDecl();
     const ASTRecordLayout &BaseLayout = Context.getASTRecordLayout(BaseDecl);
-    bool HasVtordisp = HasVtorDispSet.count(BaseDecl) > 0;
+    bool HasVtordisp = HasVtorDispSet.contains(BaseDecl);
     // Insert padding between two bases if the left first one is zero sized or
     // contains a zero sized subobject and the right is zero sized or one leads
     // with a zero sized base.  The padding between virtual bases is 4
index 2c3aa36af195e4dc94ef17b96abd42170b9e36e6..ab18d2f9e1f2e1229d600f77f4e19d989fdbadf6 100644 (file)
@@ -3454,7 +3454,7 @@ static void removeRedundantPaths(std::list<FullPathTy> &FullPaths) {
       if (&SpecificPath == &OtherPath)
         continue;
       if (llvm::all_of(SpecificPath, [&](const BaseSubobject &BSO) {
-            return OtherPath.count(BSO) != 0;
+            return OtherPath.contains(BSO);
           })) {
         return true;
       }
index 5188ebc896007578d999fc25f8cbf81de992cf4e..9f4e0f12e0232c176caa4a6658d9860821275216 100644 (file)
@@ -12373,7 +12373,7 @@ bool CGOpenMPRuntime::isNontemporalDecl(const ValueDecl *VD) const {
 
   return llvm::any_of(
       CGM.getOpenMPRuntime().NontemporalDeclsStack,
-      [VD](const NontemporalDeclsSet &Set) { return Set.count(VD) > 0; });
+      [VD](const NontemporalDeclsSet &Set) { return Set.contains(VD); });
 }
 
 void CGOpenMPRuntime::LastprivateConditionalRAII::tryToDisableInnerAnalysis(
index 51ac96f6b2892cdd671499db5a11a4b0c7c90555..f8cf8a3d5dc8bc9b5047d8fb6245d301fcfa8631 100644 (file)
@@ -2711,8 +2711,7 @@ static void CheckProtocolMethodDefs(Sema &S,
       ProtocolsExplictImpl.reset(new ProtocolNameSet);
       findProtocolsWithExplicitImpls(Super, *ProtocolsExplictImpl);
     }
-    if (ProtocolsExplictImpl->find(PDecl->getIdentifier()) !=
-        ProtocolsExplictImpl->end())
+    if (ProtocolsExplictImpl->contains(PDecl->getIdentifier()))
       return;
 
     // If no super class conforms to the protocol, we should not search
index fa55f925d117b430cfe23aadc03a9b5415b16e2e..888113cf93d8c840ef2af464f1f6c493d9501d9b 100644 (file)
@@ -515,7 +515,7 @@ public:
   /// Checks if the specified declaration was used in the inner scan directive.
   bool isUsedInScanDirective(ValueDecl *D) const {
     if (const SharingMapTy *Stack = getTopOfStackOrNull())
-      return Stack->UsedInScanDirective.count(D) > 0;
+      return Stack->UsedInScanDirective.contains(D);
     return false;
   }
 
@@ -1040,7 +1040,7 @@ public:
   // Return set of mapped classes types
   bool isClassPreviouslyMapped(QualType QT) const {
     const SharingMapTy &StackElem = getTopOfStack();
-    return StackElem.MappedClassesQualTypes.count(QT) != 0;
+    return StackElem.MappedClassesQualTypes.contains(QT);
   }
 
   /// Adds global declare target to the parent target region.
@@ -1079,7 +1079,7 @@ public:
   }
   /// Checks if the decl is implicitly firstprivate in the task-based region.
   bool isImplicitTaskFirstprivate(Decl *D) const {
-    return getTopOfStack().ImplicitTaskFirstprivates.count(D) > 0;
+    return getTopOfStack().ImplicitTaskFirstprivates.contains(D);
   }
 
   /// Marks decl as used in uses_allocators clause as the allocator.
index 94ab9ad3b2153d1ca0389a266392ab17ec8eaa94..b57c5dc6de562765feba0d2ff887e2c42fd8519f 100644 (file)
@@ -949,7 +949,7 @@ void NonLocalizedStringChecker::checkPostCall(const CallEvent &Call,
   const IdentifierInfo *Identifier = Call.getCalleeIdentifier();
 
   SVal sv = Call.getReturnValue();
-  if (isAnnotatedAsReturningLocalized(D) || LSF.count(Identifier) != 0) {
+  if (isAnnotatedAsReturningLocalized(D) || LSF.contains(Identifier)) {
     setLocalizedState(sv, C);
   } else if (isNSStringType(RT, C.getASTContext()) &&
              !hasLocalizedState(sv, C)) {
index 1c17b8408ee7b5d987efe407062bee140e4b25fb..ec2628c7eca9eb96fd8c103bf002e9eec8fcef39 100644 (file)
@@ -107,7 +107,7 @@ void Object::removeSections(function_ref<bool(const Section &)> ToRemove) {
           // section,
           // remove those as well as nothing will include them (and we can't
           // leave them dangling).
-          if (RemovedSections.count(Sym.AssociativeComdatTargetSectionId) == 1)
+          if (RemovedSections.contains(Sym.AssociativeComdatTargetSectionId))
             AssociatedSections.insert(Sym.TargetSectionId);
           return RemovedSections.contains(Sym.TargetSectionId);
         });