forked from OSchip/llvm-project
Provide a mode for ImmutableMap/ImmutableSet to not automatically canonicalize the internal functional AVL trees. This should speedup clients that use ImmutableMap/ImmutableSet but don't require fast comparisons of maps.
llvm-svn: 84010
This commit is contained in:
parent
423e42b371
commit
5d81cb2084
|
@ -80,23 +80,25 @@ public:
|
||||||
|
|
||||||
class Factory {
|
class Factory {
|
||||||
typename TreeTy::Factory F;
|
typename TreeTy::Factory F;
|
||||||
|
const bool Canonicalize;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Factory() {}
|
Factory(bool canonicalize = true)
|
||||||
|
: Canonicalize(canonicalize) {}
|
||||||
|
|
||||||
Factory(BumpPtrAllocator& Alloc)
|
Factory(BumpPtrAllocator& Alloc, bool canonicalize = true)
|
||||||
: F(Alloc) {}
|
: F(Alloc), Canonicalize(canonicalize) {}
|
||||||
|
|
||||||
ImmutableMap GetEmptyMap() { return ImmutableMap(F.GetEmptyTree()); }
|
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) {
|
||||||
TreeTy *T = F.Add(Old.Root, std::make_pair<key_type,data_type>(K,D));
|
TreeTy *T = F.Add(Old.Root, std::make_pair<key_type,data_type>(K,D));
|
||||||
return ImmutableMap(F.GetCanonicalTree(T));
|
return ImmutableMap(Canonicalize ? F.GetCanonicalTree(T): T);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImmutableMap Remove(ImmutableMap Old, key_type_ref K) {
|
ImmutableMap Remove(ImmutableMap Old, key_type_ref K) {
|
||||||
TreeTy *T = F.Remove(Old.Root,K);
|
TreeTy *T = F.Remove(Old.Root,K);
|
||||||
return ImmutableMap(F.GetCanonicalTree(T));
|
return ImmutableMap(Canonicalize ? F.GetCanonicalTree(T): T);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -947,15 +947,19 @@ public:
|
||||||
|
|
||||||
class Factory {
|
class Factory {
|
||||||
typename TreeTy::Factory F;
|
typename TreeTy::Factory F;
|
||||||
|
const bool Canonicalize;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Factory() {}
|
Factory(bool canonicalize = true)
|
||||||
|
: Canonicalize(canonicalize) {}
|
||||||
|
|
||||||
Factory(BumpPtrAllocator& Alloc)
|
Factory(BumpPtrAllocator& Alloc, bool canonicalize = true)
|
||||||
: F(Alloc) {}
|
: F(Alloc), Canonicalize(canonicalize) {}
|
||||||
|
|
||||||
/// GetEmptySet - Returns an immutable set that contains no elements.
|
/// GetEmptySet - Returns an immutable set that contains no elements.
|
||||||
ImmutableSet GetEmptySet() { return ImmutableSet(F.GetEmptyTree()); }
|
ImmutableSet GetEmptySet() {
|
||||||
|
return ImmutableSet(F.GetEmptyTree());
|
||||||
|
}
|
||||||
|
|
||||||
/// Add - Creates a new immutable set that contains all of the values
|
/// Add - Creates a new immutable set that contains all of the values
|
||||||
/// of the original set with the addition of the specified value. If
|
/// of the original set with the addition of the specified value. If
|
||||||
|
@ -965,7 +969,8 @@ public:
|
||||||
/// The memory allocated to represent the set is released when the
|
/// The memory allocated to represent the set is released when the
|
||||||
/// factory object that created the set is destroyed.
|
/// factory object that created the set is destroyed.
|
||||||
ImmutableSet Add(ImmutableSet Old, value_type_ref V) {
|
ImmutableSet Add(ImmutableSet Old, value_type_ref V) {
|
||||||
return ImmutableSet(F.GetCanonicalTree(F.Add(Old.Root,V)));
|
TreeTy *NewT = F.Add(Old.Root, V);
|
||||||
|
return ImmutableSet(Canonicalize ? F.GetCanonicalTree(NewT) : NewT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove - Creates a new immutable set that contains all of the values
|
/// Remove - Creates a new immutable set that contains all of the values
|
||||||
|
@ -976,7 +981,8 @@ public:
|
||||||
/// The memory allocated to represent the set is released when the
|
/// The memory allocated to represent the set is released when the
|
||||||
/// factory object that created the set is destroyed.
|
/// factory object that created the set is destroyed.
|
||||||
ImmutableSet Remove(ImmutableSet Old, value_type_ref V) {
|
ImmutableSet Remove(ImmutableSet Old, value_type_ref V) {
|
||||||
return ImmutableSet(F.GetCanonicalTree(F.Remove(Old.Root,V)));
|
TreeTy *NewT = F.Remove(Old.Root, V);
|
||||||
|
return ImmutableSet(Canonicalize ? F.GetCanonicalTree(NewT) : NewT);
|
||||||
}
|
}
|
||||||
|
|
||||||
BumpPtrAllocator& getAllocator() { return F.getAllocator(); }
|
BumpPtrAllocator& getAllocator() { return F.getAllocator(); }
|
||||||
|
|
Loading…
Reference in New Issue