================
@@ -76,14 +86,12 @@ class InnerPointerChecker
                                      BugReporterContext &BRC,
                                      PathSensitiveBugReport &BR) override;
 
-    // FIXME: Scan the map once in the visitor's constructor and do a direct
-    // lookup by region.
     bool isSymbolTracked(ProgramStateRef State, SymbolRef Sym) {
-      RawPtrMapTy Map = State->get<RawPtrMap>();
-      for (const auto &Entry : Map) {
-        if (Entry.second.contains(Sym))
-          return true;
-      }
+      // ContainerRegion is cached in the constructor to avoid
+      // repeated O(n) map scans.
+      const PtrSet *PS = State->get<RawPtrMap>(ContainerRegion);
+      if(PS != nullptr && PS->contains(Sym))
+        return true;
       return false;
     }
----------------
steakhal wrote:

I think this should be simpler:
```c++
    bool isSymbolTracked(ProgramStateRef State, SymbolRef Sym) {
      const PtrSet *PS = State->get<RawPtrMap>(ContainerRegion);
      return PS && PS->contains(Sym);
    }
```
No need for comments here.

https://github.com/llvm/llvm-project/pull/185796
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to