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

via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 16 06:43:29 PDT 2024


Author: Kazu Hirata
Date: 2024-09-16T06:43:26-07:00
New Revision: 91591794514fa6f17d87285acb41e3dba1eee5e5

URL: https://github.com/llvm/llvm-project/commit/91591794514fa6f17d87285acb41e3dba1eee5e5
DIFF: https://github.com/llvm/llvm-project/commit/91591794514fa6f17d87285acb41e3dba1eee5e5.diff

LOG: [Format] Avoid repeated hash lookups (NFC) (#108794)

Added: 
    

Modified: 
    clang/lib/Format/MacroExpander.cpp

Removed: 
    


################################################################################
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