From f60cc473b82b16edc448199c84e612c1e5c3014c Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Mon, 15 May 2023 13:28:07 -0700 Subject: [PATCH] [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 --- clang/lib/Serialization/ASTWriter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 06d758b..07a577a 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -3645,13 +3645,13 @@ void ASTWriter::WriteIdentifierTable(Preprocessor &PP, // file. SmallVector 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>()); 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. -- 2.7.4