[clang] 2deebc0 - [RFC] Add and sort decl to maintain order instead of inserting in order
Ivan Murashko via cfe-commits
cfe-commits at lists.llvm.org
Tue May 3 09:09:49 PDT 2022
Author: Kugan Vivekanandarajah
Date: 2022-05-03T17:06:22+01:00
New Revision: 2deebc0048f92811dc92c7e41d357683b84febf7
URL: https://github.com/llvm/llvm-project/commit/2deebc0048f92811dc92c7e41d357683b84febf7
DIFF: https://github.com/llvm/llvm-project/commit/2deebc0048f92811dc92c7e41d357683b84febf7.diff
LOG: [RFC] Add and sort decl to maintain order instead of inserting in order
ASTWriter::associateDeclWithFile shows a lot in clangd perf profile due to O(n^2) behaviour in insertion of DeclIDs in SortedFileDeclIDs. Instead of doing that, this patch just appends it to the DeclIDs vector and sorts them at the end.
Reviewed By: akyrtzi
Differential Revision: https://reviews.llvm.org/D124840
Added:
Modified:
clang/lib/Serialization/ASTWriter.cpp
Removed:
################################################################################
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 189d1a914ec31..228bd9aa08db4 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -3114,6 +3114,7 @@ void ASTWriter::WriteFileDeclIDsMap() {
for (auto &FileDeclEntry : SortedFileDeclIDs) {
DeclIDInFileInfo &Info = *FileDeclEntry.second;
Info.FirstDeclIndex = FileGroupedDeclIDs.size();
+ llvm::stable_sort(Info.DeclIDs);
for (auto &LocDeclEntry : Info.DeclIDs)
FileGroupedDeclIDs.push_back(LocDeclEntry.second);
}
@@ -5462,16 +5463,7 @@ void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) {
std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID);
LocDeclIDsTy &Decls = Info->DeclIDs;
-
- if (Decls.empty() || Decls.back().first <= Offset) {
- Decls.push_back(LocDecl);
- return;
- }
-
- LocDeclIDsTy::iterator I =
- llvm::upper_bound(Decls, LocDecl, llvm::less_first());
-
- Decls.insert(I, LocDecl);
+ Decls.push_back(LocDecl);
}
unsigned ASTWriter::getAnonymousDeclarationNumber(const NamedDecl *D) {
More information about the cfe-commits
mailing list