[llvm-commits] [llvm] r53485 - /llvm/trunk/include/llvm/ADT/ImmutableList.h

Ted Kremenek kremenek at apple.com
Fri Jul 11 15:43:07 PDT 2008


Author: kremenek
Date: Fri Jul 11 17:43:07 2008
New Revision: 53485

URL: http://llvm.org/viewvc/llvm-project?rev=53485&view=rev
Log:
Minor tweaks to the ImmutableList iterator interface.
Added partial specialization of DenseMapInfo<T> for ImmutableList.

Modified:
    llvm/trunk/include/llvm/ADT/ImmutableList.h

Modified: llvm/trunk/include/llvm/ADT/ImmutableList.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ImmutableList.h?rev=53485&r1=53484&r2=53485&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/ImmutableList.h (original)
+++ llvm/trunk/include/llvm/ADT/ImmutableList.h Fri Jul 11 17:43:07 2008
@@ -73,7 +73,7 @@
   // This constructor should normally only be called by ImmutableListFactory<T>.
   // There may be cases, however, when one needs to extract the internal pointer
   // and reconstruct a list object from that pointer.
-  ImmutableList(ImmutableListImpl<T>* x) : X(x) {}
+  ImmutableList(ImmutableListImpl<T>* x = 0) : X(x) {}
 
   ImmutableListImpl<T>* getInternalPointer() const {
     return X;
@@ -88,7 +88,8 @@
     iterator& operator++() { L = L->getTail(); return *this; }
     bool operator==(const iterator& I) const { return L == I.L; }
     bool operator!=(const iterator& I) const { return L != I.L; }
-    ImmutableList operator*() const { return L; }
+    const value_type& operator*() const { return L->getHead(); }    
+    ImmutableList getList() const { return L; }    
   };
 
   /// begin - Returns an iterator referring to the head of the list, or
@@ -186,6 +187,29 @@
   }
 };
   
+//===----------------------------------------------------------------------===//  
+// Partially-specialized Traits.
+//===----------------------------------------------------------------------===//  
+  
+template<typename T> struct DenseMapInfo;
+template<typename T> struct DenseMapInfo<ImmutableList<T> > {
+  static inline ImmutableList<T> getEmptyKey() {
+    return reinterpret_cast<ImmutableListImpl<T>*>(-1);
+  }
+  static inline ImmutableList<T> getTombstoneKey() {
+    return reinterpret_cast<ImmutableListImpl<T>*>(-2);
+  }
+  static unsigned getHashValue(ImmutableList<T> X) {
+    uintptr_t PtrVal = reinterpret_cast<uintptr_t>(X.getInternalPointer());
+    return (unsigned((uintptr_t)PtrVal) >> 4) ^ 
+           (unsigned((uintptr_t)PtrVal) >> 9);
+  }
+  static bool isEqual(ImmutableList<T> X1, ImmutableList<T> X2) {
+    return X1 == X2;
+  }
+  static bool isPod() { return true; }
+};
+  
 } // end llvm namespace
 
 #endif





More information about the llvm-commits mailing list