[clang] [Format] Avoid repeated hash lookups (NFC) (PR #108794)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 15 23:42:26 PDT 2024


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

None

>From e5a86bbb661aba2d68acff0b28944f523adb490a Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 15 Sep 2024 01:35:59 -0700
Subject: [PATCH] [Format] Avoid repeated hash lookups (NFC)

---
 clang/lib/Format/MacroExpander.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/MacroExpander.cpp b/clang/lib/Format/MacroExpander.cpp
index 5768ff37fefcda..fd2a16894d643d 100644
--- a/clang/lib/Format/MacroExpander.cpp
+++ b/clang/lib/Format/MacroExpander.cpp
@@ -191,9 +191,10 @@ MacroExpander::expand(FormatToken *ID,
   auto expandArgument = [&](FormatToken *Tok) -> bool {
     // If the current token references a parameter, expand the corresponding
     // argument.
-    if (Tok->isNot(tok::identifier) || ExpandedArgs.contains(Tok->TokenText))
+    if (Tok->isNot(tok::identifier))
+      return false;
+    if (!ExpandedArgs.insert(Tok->TokenText).second)
       return false;
-    ExpandedArgs.insert(Tok->TokenText);
     auto I = Def.ArgMap.find(Tok->TokenText);
     if (I == Def.ArgMap.end())
       return false;



More information about the cfe-commits mailing list