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

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 9 21:21:30 PST 2025


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

None

>From 38fe282d1e50b35d46ec368b86edba58e1898090 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 9 Feb 2025 13:54:03 -0800
Subject: [PATCH] [AST] Avoid repeated hash lookups (NFC)

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

diff --git a/clang/lib/AST/RawCommentList.cpp b/clang/lib/AST/RawCommentList.cpp
index fddedd3a31856a3..9658c6ab3d39dd6 100644
--- a/clang/lib/AST/RawCommentList.cpp
+++ b/clang/lib/AST/RawCommentList.cpp
@@ -287,13 +287,13 @@ void RawCommentList::addComment(const RawComment &RC,
 
   // If this is the first Doxygen comment, save it (because there isn't
   // anything to merge it with).
-  if (OrderedComments[CommentFile].empty()) {
-    OrderedComments[CommentFile][CommentOffset] =
-        new (Allocator) RawComment(RC);
+  auto &OC = OrderedComments[CommentFile];
+  if (OC.empty()) {
+    OC[CommentOffset] = new (Allocator) RawComment(RC);
     return;
   }
 
-  const RawComment &C1 = *OrderedComments[CommentFile].rbegin()->second;
+  const RawComment &C1 = *OC.rbegin()->second;
   const RawComment &C2 = RC;
 
   // Merge comments only if there is only whitespace between them.



More information about the cfe-commits mailing list