From 69aecc6252bf4a5ee59f9b51c3728ea07b6342bf Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 27 Oct 2010 20:23:41 +0000 Subject: [PATCH] Lazily load the next friend in the chain of FriendDecls, to eliminate some excessive recursion and deserialization. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117480 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclFriend.h | 13 +++++++++---- lib/Serialization/ASTReaderDecl.cpp | 2 +- lib/Serialization/ASTWriterDecl.cpp | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/clang/AST/DeclFriend.h b/include/clang/AST/DeclFriend.h index 10befe0831..20d6da19b8 100644 --- a/include/clang/AST/DeclFriend.h +++ b/include/clang/AST/DeclFriend.h @@ -43,7 +43,7 @@ private: FriendUnion Friend; // A pointer to the next friend in the sequence. - FriendDecl *NextFriend; + LazyDeclPtr NextFriend; // Location of the 'friend' specifier. SourceLocation FriendLoc; @@ -60,14 +60,19 @@ private: SourceLocation FriendL) : Decl(Decl::Friend, DC, L), Friend(Friend), - NextFriend(0), + NextFriend(), FriendLoc(FriendL), UnsupportedFriend(false) { } explicit FriendDecl(EmptyShell Empty) - : Decl(Decl::Friend, Empty), NextFriend(0) { } + : Decl(Decl::Friend, Empty), NextFriend() { } + FriendDecl *getNextFriend() { + return cast_or_null( + NextFriend.get(getASTContext().getExternalSource())); + } + public: static FriendDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L, FriendUnion Friend_, @@ -129,7 +134,7 @@ public: friend_iterator &operator++() { assert(Ptr && "attempt to increment past end of friend list"); - Ptr = Ptr->NextFriend; + Ptr = Ptr->getNextFriend(); return *this; } diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 4b1d48162e..322a67176f 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -933,7 +933,7 @@ void ASTDeclReader::VisitFriendDecl(FriendDecl *D) { D->Friend = GetTypeSourceInfo(Record, Idx); else D->Friend = cast(Reader.GetDecl(Record[Idx++])); - D->NextFriend = cast_or_null(Reader.GetDecl(Record[Idx++])); + D->NextFriend = Record[Idx++]; D->UnsupportedFriend = (Record[Idx++] != 0); D->FriendLoc = ReadSourceLocation(Record, Idx); } diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index 4e479b33de..46f62b7d84 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -803,7 +803,7 @@ void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) { Writer.AddTypeSourceInfo(D->Friend.get(), Record); else Writer.AddDeclRef(D->Friend.get(), Record); - Writer.AddDeclRef(D->NextFriend, Record); + Writer.AddDeclRef(D->getNextFriend(), Record); Record.push_back(D->UnsupportedFriend); Writer.AddSourceLocation(D->FriendLoc, Record); Code = serialization::DECL_FRIEND; -- 2.40.0