ThreadLocal: Return a mutable pointer if templated with a non-const type
[oota-llvm.git] / include / llvm / Support / OnDiskHashTable.h
index 14bfd9ad4f963cb9c32f0177f4b6e094e8400da3..b039faec0b5a2d7762f607aded0ca1b42ffd816c 100644 (file)
@@ -11,8 +11,8 @@
 /// \brief Defines facilities for reading and writing on-disk hash tables.
 ///
 //===----------------------------------------------------------------------===//
-#ifndef LLVM_SUPPORT_ON_DISK_HASH_TABLE_H
-#define LLVM_SUPPORT_ON_DISK_HASH_TABLE_H
+#ifndef LLVM_SUPPORT_ONDISKHASHTABLE_H
+#define LLVM_SUPPORT_ONDISKHASHTABLE_H
 
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/AlignOf.h"
@@ -56,11 +56,6 @@ namespace llvm {
 /// };
 /// \endcode
 template <typename Info> class OnDiskChainedHashTableGenerator {
-  typedef typename Info::offset_type offset_type;
-  offset_type NumBuckets;
-  offset_type NumEntries;
-  llvm::BumpPtrAllocator BA;
-
   /// \brief A single item in the hash table.
   class Item {
   public:
@@ -71,9 +66,14 @@ template <typename Info> class OnDiskChainedHashTableGenerator {
 
     Item(typename Info::key_type_ref Key, typename Info::data_type_ref Data,
          Info &InfoObj)
-        : Key(Key), Data(Data), Next(0), Hash(InfoObj.ComputeHash(Key)) {}
+        : Key(Key), Data(Data), Next(nullptr), Hash(InfoObj.ComputeHash(Key)) {}
   };
 
+  typedef typename Info::offset_type offset_type;
+  offset_type NumBuckets;
+  offset_type NumEntries;
+  llvm::SpecificBumpPtrAllocator<Item> BA;
+
   /// \brief A linked list of values in a particular hash bucket.
   class Bucket {
   public:
@@ -102,7 +102,7 @@ private:
     for (size_t I = 0; I < NumBuckets; ++I)
       for (Item *E = Buckets[I].Head; E;) {
         Item *N = E->Next;
-        E->Next = 0;
+        E->Next = nullptr;
         insert(NewBuckets, NewSize, E);
         E = N;
       }
@@ -129,8 +129,7 @@ public:
     ++NumEntries;
     if (4 * NumEntries >= 3 * NumBuckets)
       resize(NumBuckets * 2);
-    insert(Buckets, NumBuckets,
-           new (BA.Allocate<Item>()) Item(Key, Data, InfoObj));
+    insert(Buckets, NumBuckets, new (BA.Allocate()) Item(Key, Data, InfoObj));
   }
 
   /// \brief Emit the table to Out, which must not be at offset 0.
@@ -273,7 +272,7 @@ public:
     Info *InfoObj;
 
   public:
-    iterator() : Data(0), Len(0) {}
+    iterator() : Data(nullptr), Len(0) {}
     iterator(const internal_key_type K, const unsigned char *D, offset_type L,
              Info *InfoObj)
         : Key(K), Data(D), Len(L), InfoObj(InfoObj) {}
@@ -406,7 +405,8 @@ public:
         : Ptr(Ptr), NumItemsInBucketLeft(0), NumEntriesLeft(NumEntries),
           InfoObj(InfoObj) {}
     key_iterator()
-        : Ptr(0), NumItemsInBucketLeft(0), NumEntriesLeft(0), InfoObj(0) {}
+        : Ptr(nullptr), NumItemsInBucketLeft(0), NumEntriesLeft(0),
+          InfoObj(0) {}
 
     friend bool operator==(const key_iterator &X, const key_iterator &Y) {
       return X.NumEntriesLeft == Y.NumEntriesLeft;
@@ -478,7 +478,8 @@ public:
         : Ptr(Ptr), NumItemsInBucketLeft(0), NumEntriesLeft(NumEntries),
           InfoObj(InfoObj) {}
     data_iterator()
-        : Ptr(0), NumItemsInBucketLeft(0), NumEntriesLeft(0), InfoObj(0) {}
+        : Ptr(nullptr), NumItemsInBucketLeft(0), NumEntriesLeft(0),
+          InfoObj(nullptr) {}
 
     bool operator==(const data_iterator &X) const {
       return X.NumEntriesLeft == NumEntriesLeft;
@@ -567,4 +568,4 @@ public:
 
 } // end namespace llvm
 
-#endif // LLVM_SUPPORT_ON_DISK_HASH_TABLE_H
+#endif