[llvm] [Support] Avoid repeated hash lookups (NFC) (PR #132517)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 21 21:11:03 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/132517.diff
1 Files Affected:
- (modified) llvm/lib/Support/SuffixTree.cpp (+3-2)
``````````diff
diff --git a/llvm/lib/Support/SuffixTree.cpp b/llvm/lib/Support/SuffixTree.cpp
index 5e58310e1128b..5abcead5037f4 100644
--- a/llvm/lib/Support/SuffixTree.cpp
+++ b/llvm/lib/Support/SuffixTree.cpp
@@ -193,7 +193,8 @@ unsigned SuffixTree::extend(unsigned EndIdx, unsigned SuffixesToAdd) {
unsigned FirstChar = Str[Active.Idx];
// Have we inserted anything starting with FirstChar at the current node?
- if (Active.Node->Children.count(FirstChar) == 0) {
+ if (auto It = Active.Node->Children.find(FirstChar);
+ It == Active.Node->Children.end()) {
// If not, then we can just insert a leaf and move to the next step.
insertLeaf(*Active.Node, EndIdx, FirstChar);
@@ -206,7 +207,7 @@ unsigned SuffixTree::extend(unsigned EndIdx, unsigned SuffixesToAdd) {
} else {
// There's a match with FirstChar, so look for the point in the tree to
// insert a new node.
- SuffixTreeNode *NextNode = Active.Node->Children[FirstChar];
+ SuffixTreeNode *NextNode = It->second;
unsigned SubstringLen = numElementsInSubstring(NextNode);
``````````
</details>
https://github.com/llvm/llvm-project/pull/132517
More information about the llvm-commits
mailing list