[llvm] [TableGen] Avoid repeated map lookups (NFC) (PR #123699)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 20 23:03:11 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/123699.diff
1 Files Affected:
- (modified) llvm/utils/TableGen/Basic/VTEmitter.cpp (+7-6)
``````````diff
diff --git a/llvm/utils/TableGen/Basic/VTEmitter.cpp b/llvm/utils/TableGen/Basic/VTEmitter.cpp
index d02932dd5e7fca..07840d397bb156 100644
--- a/llvm/utils/TableGen/Basic/VTEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/VTEmitter.cpp
@@ -109,12 +109,13 @@ void VTEmitter::run(raw_ostream &OS) {
auto UpdateVTRange = [&VTRanges](const char *Key, StringRef Name,
bool Valid) {
if (Valid) {
- if (!VTRanges.count(Key))
- VTRanges[Key].First = Name;
- assert(!VTRanges[Key].Closed && "Gap detected!");
- VTRanges[Key].Last = Name;
- } else if (VTRanges.count(Key)) {
- VTRanges[Key].Closed = true;
+ auto [It, Inserted] = VTRanges.try_emplace(Key);
+ if (Inserted)
+ It->second.First = Name;
+ assert(!It->second.Closed && "Gap detected!");
+ It->second.Last = Name;
+ } else if (auto It = VTRanges.find(Key); It != VTRanges.end()) {
+ It->second.Closed = true;
}
};
``````````
</details>
https://github.com/llvm/llvm-project/pull/123699
More information about the llvm-commits
mailing list