https://github.com/melver created https://github.com/llvm/llvm-project/pull/141500
In ScopedLockableFactEntry::unlock(), we can avoid a second search, pop_back(), and push_back() if we use the already obtained iterator into the FactSet to replace the old FactEntry and take its position in the vector. >From b77f2a1ebf98bde647ee535dbd1ab0c24dbdfdb3 Mon Sep 17 00:00:00 2001 From: Marco Elver <el...@google.com> Date: Fri, 25 Apr 2025 18:51:16 +0200 Subject: [PATCH] Thread Safety Analysis: Use replaceLock instead of removeLock+addLock In ScopedLockableFactEntry::unlock(), we can avoid a second search, pop_back(), and push_back() if we use the already obtained iterator into the FactSet to replace the old FactEntry and take its position in the vector. --- clang/lib/Analysis/ThreadSafety.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp index 198e324414be9..9dffb8fcd2204 100644 --- a/clang/lib/Analysis/ThreadSafety.cpp +++ b/clang/lib/Analysis/ThreadSafety.cpp @@ -1071,9 +1071,9 @@ class ScopedLockableFactEntry : public FactEntry { return; } - FSet.removeLock(FactMan, Cp); - FSet.addLock(FactMan, - std::make_unique<LockableFactEntry>(!Cp, LK_Exclusive, loc)); + FSet.replaceLock( + FactMan, It, + std::make_unique<LockableFactEntry>(!Cp, LK_Exclusive, loc)); } else if (Handler) { SourceLocation PrevLoc; if (const FactEntry *Neg = FSet.findLock(FactMan, !Cp)) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits