[clang] [AST] Avoid repeated hash lookups (NFC) (PR #123285)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 16 21:31:01 PST 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/123285

None

>From 1baa9c7445a6e65a6c9086994e728db463fe6a5f Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 16 Jan 2025 09:56:31 -0800
Subject: [PATCH] [AST] Avoid repeated hash lookups (NFC)

---
 clang/lib/AST/VTableBuilder.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/VTableBuilder.cpp b/clang/lib/AST/VTableBuilder.cpp
index e941c3bedb0a7e..fa3055dd1206f4 100644
--- a/clang/lib/AST/VTableBuilder.cpp
+++ b/clang/lib/AST/VTableBuilder.cpp
@@ -3831,8 +3831,8 @@ const VirtualBaseInfo &MicrosoftVTableContext::computeVBTableRelatedInformation(
   unsigned VBTableIndex = 1 + VBI->VBTableIndices.size();
   for (const auto &VB : RD->vbases()) {
     const CXXRecordDecl *CurVBase = VB.getType()->getAsCXXRecordDecl();
-    if (!VBI->VBTableIndices.count(CurVBase))
-      VBI->VBTableIndices[CurVBase] = VBTableIndex++;
+    if (VBI->VBTableIndices.try_emplace(CurVBase, VBTableIndex).second)
+      ++VBTableIndex;
   }
 
   return *VBI;



More information about the cfe-commits mailing list