[llvm-commits] [llvm] r169532 - /llvm/trunk/include/llvm/ADT/ImmutableMap.h

Jordan Rose jordan_rose at apple.com
Thu Dec 6 11:01:25 PST 2012


Author: jrose
Date: Thu Dec  6 13:01:24 2012
New Revision: 169532

URL: http://llvm.org/viewvc/llvm-project?rev=169532&view=rev
Log:
Allow modifying an ImmutableMap without canonicalizing it immediately.

This is an alternative to the ImmutableMapRef interface where a factory
should still be canonicalizing by default, but in certain cases an
improvement can be made by delaying the canonicalization.

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

Modified: llvm/trunk/include/llvm/ADT/ImmutableMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ImmutableMap.h?rev=169532&r1=169531&r2=169532&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/ImmutableMap.h (original)
+++ llvm/trunk/include/llvm/ADT/ImmutableMap.h Thu Dec  6 13:01:24 2012
@@ -96,27 +96,40 @@
 
   class Factory {
     typename TreeTy::Factory F;
-    const bool Canonicalize;
+    const bool Canonicalizing;
 
   public:
     Factory(bool canonicalize = true)
-      : Canonicalize(canonicalize) {}
+      : Canonicalizing(canonicalize) {}
     
     Factory(BumpPtrAllocator& Alloc, bool canonicalize = true)
-      : F(Alloc), Canonicalize(canonicalize) {}
+      : F(Alloc), Canonicalizing(canonicalize) {}
 
     ImmutableMap getEmptyMap() { return ImmutableMap(F.getEmptyTree()); }
 
-    ImmutableMap add(ImmutableMap Old, key_type_ref K, data_type_ref D) {
+    ImmutableMap add(ImmutableMap Old, key_type_ref K, data_type_ref D,
+                     bool Canonicalize) {
       TreeTy *T = F.add(Old.Root, std::pair<key_type,data_type>(K,D));
       return ImmutableMap(Canonicalize ? F.getCanonicalTree(T): T);
     }
 
-    ImmutableMap remove(ImmutableMap Old, key_type_ref K) {
+    ImmutableMap add(ImmutableMap Old, key_type_ref K, data_type_ref D) {
+      return add(Old, K, D, Canonicalizing);
+    }
+
+    ImmutableMap remove(ImmutableMap Old, key_type_ref K, bool Canonicalize) {
       TreeTy *T = F.remove(Old.Root,K);
       return ImmutableMap(Canonicalize ? F.getCanonicalTree(T): T);
     }
 
+    ImmutableMap remove(ImmutableMap Old, key_type_ref K) {
+      return remove(Old, K, Canonicalizing);
+    }
+
+    ImmutableMap getCanonicalMap(ImmutableMap Map) {
+      return ImmutableMap(F.getCanonicalTree(Map.Root));
+    }
+
     typename TreeTy::Factory *getTreeFactory() const {
       return const_cast<typename TreeTy::Factory *>(&F);
     }





More information about the llvm-commits mailing list