[clang] f60cc47 - [clang][modules] NFC: Only sort interesting identifiers

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Mon May 15 13:28:56 PDT 2023


Author: Jan Svoboda
Date: 2023-05-15T13:28:10-07:00
New Revision: f60cc473b82b16edc448199c84e612c1e5c3014c

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

LOG: [clang][modules] NFC: Only sort interesting identifiers

In 9c254184 `ASTWriter` stopped writing identifiers that are not interesting. Taking it a bit further, we don't need to sort the whole identifier table, just the interesting identifiers. This reduces the size of sorted vector from ~10k (including lots of builtins) to 2 (`__VA_ARGS__` and `__VA_OPT__`) in a typical Xcode project, improving `clang-scan-deps` performance.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D150494

Added: 
    

Modified: 
    clang/lib/Serialization/ASTWriter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 06d758b36c59d..07a577a009995 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -3645,13 +3645,13 @@ void ASTWriter::WriteIdentifierTable(Preprocessor &PP,
     // file.
     SmallVector<const IdentifierInfo *, 128> IIs;
     for (const auto &ID : PP.getIdentifierTable())
-      IIs.push_back(ID.second);
-    // Sort the identifiers lexicographically before getting them references so
+      if (Trait.isInterestingNonMacroIdentifier(ID.second))
+        IIs.push_back(ID.second);
+    // Sort the identifiers lexicographically before getting the references so
     // that their order is stable.
     llvm::sort(IIs, llvm::deref<std::less<>>());
     for (const IdentifierInfo *II : IIs)
-      if (Trait.isInterestingNonMacroIdentifier(II))
-        getIdentifierRef(II);
+      getIdentifierRef(II);
 
     // Create the on-disk hash table representation. We only store offsets
     // for identifiers that appear here for the first time.


        


More information about the cfe-commits mailing list