[llvm] [Analysis] Avoid repeated hash lookups (NFC) (PR #107794)

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 8 18:56:04 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/107794.diff


1 Files Affected:

- (modified) llvm/include/llvm/Analysis/DOTGraphTraitsPass.h (+2-5) 


``````````diff
diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
index 7aea7a3b0f6d69..ba5ee1d7db4871 100644
--- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
+++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
@@ -91,12 +91,9 @@ static inline void shortenFileName(std::string &FN, unsigned char len = 250) {
     FN.resize(len);
   auto strLen = FN.length();
   while (strLen > 0) {
-    if (nameObj.find(FN) != nameObj.end()) {
-      FN.resize(--len);
-    } else {
-      nameObj.insert(FN);
+    if (nameObj.insert(FN).second)
       break;
-    }
+    FN.resize(--len);
     strLen--;
   }
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/107794


More information about the llvm-commits mailing list