diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-12-06 19:01:24 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-12-06 19:01:24 +0000 |
commit | 972f087dbbc233bff9270716f2af453b90a996d9 (patch) | |
tree | 31fbc5aa7f04e9c2ee1214236e5bfecf7f56fc19 | |
parent | b2af3a095b218700c3912574d2f1100207c0ae2c (diff) | |
download | external_llvm-972f087dbbc233bff9270716f2af453b90a996d9.zip external_llvm-972f087dbbc233bff9270716f2af453b90a996d9.tar.gz external_llvm-972f087dbbc233bff9270716f2af453b90a996d9.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169532 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/ADT/ImmutableMap.h | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/include/llvm/ADT/ImmutableMap.h b/include/llvm/ADT/ImmutableMap.h index 4883c5b..0043dc6 100644 --- a/include/llvm/ADT/ImmutableMap.h +++ b/include/llvm/ADT/ImmutableMap.h @@ -96,27 +96,40 @@ public: 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); } |