Revised implementation of BatchReadOwnedPtrs() that deserializes an
authorTed Kremenek <kremenek@apple.com>
Thu, 8 Nov 2007 00:04:50 +0000 (00:04 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 8 Nov 2007 00:04:50 +0000 (00:04 +0000)
array of pointers to not allocate a second array to contain the pointer ids.

Fixed bug in the same member function where deserialized pointers were
not being registered with the backpatcher.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43855 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Bitcode/Deserialize.h

index 5f8e137559326faeca28403e15ea17d615bb82ae..48f78bf9e5d93f7a1cd293ba6ab564fd61c61d6d 100644 (file)
@@ -168,17 +168,20 @@ public:
   }
   
   template <typename T>
-  void BatchReadOwnedPtrs(unsigned NumPtrs, T** Ptrs) {
-    llvm::SmallVector<unsigned,20> PtrIDs;
-    PtrIDs.reserve(NumPtrs);
-    
-    for (unsigned i = 0; i < NumPtrs; ++i)
-      PtrIDs.push_back(ReadInt());
-    
+  void BatchReadOwnedPtrs(unsigned NumPtrs, T** Ptrs, bool AutoRegister=true) {
     for (unsigned i = 0; i < NumPtrs; ++i)
-      Ptrs[i] = PtrIDs[i] ? SerializeTrait<T>::Materialize(*this) : NULL;
-  }
-    
+      reinterpret_cast<uintptr_t&>(Ptrs[i]) = ReadInt();
+    
+    for (unsigned i = 0; i < NumPtrs; ++i) {
+      unsigned PtrID = reinterpret_cast<uintptr_t>(Ptrs[i]);
+      T* p = PtrID ? SerializeTrait<T>::Materialize(*this) : NULL;
+      
+      if (PtrID && AutoRegister)
+        RegisterPtr(PtrID,p);
+      
+      Ptrs[i] = p;
+    }
+  }    
   
   template <typename T>
   void ReadPtr(T*& PtrRef, bool AllowBackpatch = true) {