Add an optional optimization to FoldingSet to allow ID values to be
authorDan Gohman <gohman@apple.com>
Mon, 13 Jul 2009 18:25:44 +0000 (18:25 +0000)
committerDan Gohman <gohman@apple.com>
Mon, 13 Jul 2009 18:25:44 +0000 (18:25 +0000)
stored rather than recomputed on each bucket traversal.

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

include/llvm/ADT/FoldingSet.h

index 1bcff3dc9eb3f30565f4fa3b196f5227992a6056..1465d04f4ebcfc0fc1b0e32d726e101421661ddb 100644 (file)
@@ -438,6 +438,20 @@ public:
   operator const T&() const { return data; }
 };
 
+//===----------------------------------------------------------------------===//
+/// FastFoldingSetNode - This is a subclass of FoldingSetNode which stores
+/// a FoldingSetNodeID value rather than requiring the node to recompute it
+/// each time it is needed. This trades space for speed (which can be
+/// significant if the ID is long), and it also permits nodes to drop
+/// information that would otherwise only be required for recomputing an ID.
+class FastFoldingSetNode : public FoldingSetNode {
+  FoldingSetNodeID FastID;
+protected:
+  explicit FastFoldingSetNode(const FoldingSetNodeID &ID) : FastID(ID) {}
+public:
+  void Profile(FoldingSetNodeID& ID) { ID = FastID; }
+};
+
 //===----------------------------------------------------------------------===//
 // Partial specializations of FoldingSetTrait.