]> granicus.if.org Git - clang/commitdiff
Lazily load the next friend in the chain of FriendDecls, to eliminate
authorDouglas Gregor <dgregor@apple.com>
Wed, 27 Oct 2010 20:23:41 +0000 (20:23 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 27 Oct 2010 20:23:41 +0000 (20:23 +0000)
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
lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriterDecl.cpp

index 10befe0831673e9d43151de4984ee858099d89e6..20d6da19b8ca0d95c57d0a5897be63db1be3b843 100644 (file)
@@ -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<FriendDecl>(
+                          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;
   }
 
index 4b1d48162e3a48c707a24674563c13bbb0795eb9..322a67176f4704f5df4cf1196eadc8f3b8156a05 100644 (file)
@@ -933,7 +933,7 @@ void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
     D->Friend = GetTypeSourceInfo(Record, Idx);
   else
     D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
-  D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
+  D->NextFriend = Record[Idx++];
   D->UnsupportedFriend = (Record[Idx++] != 0);
   D->FriendLoc = ReadSourceLocation(Record, Idx);
 }
index 4e479b33dea32f8f70bfa01119a9bce0bba71330..46f62b7d844d876f332a8bd5ea731a965cb190d7 100644 (file)
@@ -803,7 +803,7 @@ void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
     Writer.AddTypeSourceInfo(D->Friend.get<TypeSourceInfo*>(), Record);
   else
     Writer.AddDeclRef(D->Friend.get<NamedDecl*>(), 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;