[llvm-commits] [llvm] r75207 - /llvm/trunk/include/llvm/ADT/ImmutableSet.h
Ted Kremenek
kremenek at apple.com
Thu Jul 9 17:33:44 PDT 2009
Author: kremenek
Date: Thu Jul 9 19:33:43 2009
New Revision: 75207
URL: http://llvm.org/viewvc/llvm-project?rev=75207&view=rev
Log:
ImmutableMap/ImmutableSet: Allow caching of ImutAVLTree digests while the tree
is still mutable. My experiments show this reduces the amount of times we
compute a full tree digest by over 50% on very small cases, and potentially much
larger on others.
Modified:
llvm/trunk/include/llvm/ADT/ImmutableSet.h
Modified: llvm/trunk/include/llvm/ADT/ImmutableSet.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ImmutableSet.h?rev=75207&r1=75206&r2=75207&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/ImmutableSet.h (original)
+++ llvm/trunk/include/llvm/ADT/ImmutableSet.h Thu Jul 9 19:33:43 2009
@@ -283,25 +283,25 @@
void setLeft(ImutAVLTree* NewLeft) {
assert(isMutable() &&
"Only a mutable tree can have its left subtree changed.");
- assert(!hasCachedDigest() &&
- "A mutable tree cannot have a cached digest.");
-
Left = reinterpret_cast<uintptr_t>(NewLeft) | LeftFlags;
}
/// setRight - Changes the reference of the right subtree. Used internally
/// by ImutAVLFactory.
void setRight(ImutAVLTree* NewRight) {
- assert (isMutable() &&
- "Only a mutable tree can have its right subtree changed.");
+ assert(isMutable() &&
+ "Only a mutable tree can have its right subtree changed.");
Right = NewRight;
+ // Set the NoCachedDigest flag.
+ Left = Left | NoCachedDigest;
+
}
/// setHeight - Changes the height of the tree. Used internally by
/// ImutAVLFactory.
void setHeight(unsigned h) {
- assert (isMutable() && "Only a mutable tree can have its height changed.");
+ assert(isMutable() && "Only a mutable tree can have its height changed.");
Height = h;
}
@@ -330,12 +330,7 @@
return Digest;
uint32_t X = ComputeDigest(getLeft(), getRight(), getValue());
-
- if (!isMutable()) {
- Digest = X;
- MarkedCachedDigest();
- }
-
+ Digest = X;
return X;
}
};
@@ -412,7 +407,6 @@
return ( hl > hr ? hl : hr ) + 1;
}
-
static bool CompareTreeWithSection(TreeTy* T,
typename TreeTy::iterator& TI,
typename TreeTy::iterator& TE) {
@@ -454,7 +448,6 @@
// We found a collision. Perform a comparison of Contents('T')
// with Contents('L')+'V'+Contents('R').
-
typename TreeTy::iterator TI = T->begin(), TE = T->end();
// First compare Contents('L') with the (initial) contents of T.
@@ -471,17 +464,15 @@
if (!CompareTreeWithSection(R, TI, TE))
continue;
- if (TI != TE) // Contents('R') did not match suffix of 'T'.
- continue;
+ if (TI != TE)
+ continue; // Contents('R') did not match suffix of 'T'.
// Trees did match! Return 'T'.
return T;
}
// No tree with the contents: Contents('L')+'V'+Contents('R').
- // Create it.
-
- // Allocate the new tree node and insert it into the cache.
+ // Create it. Allocate the new tree node and insert it into the cache.
BumpPtrAllocator& A = getAllocator();
TreeTy* T = (TreeTy*) A.Allocate<TreeTy>();
new (T) TreeTy(L,R,V,IncrementHeight(L,R));
@@ -491,7 +482,6 @@
// Because our digest is associative and based on the contents of
// the set, this should hopefully not cause any strange bugs.
// 'T' is inserted by 'MarkImmutable'.
-
return T;
}
@@ -504,7 +494,8 @@
OldTree->setHeight(IncrementHeight(L,R));
return OldTree;
}
- else return CreateNode(L, Value(OldTree), R);
+ else
+ return CreateNode(L, Value(OldTree), R);
}
/// Balance - Used by Add_internal and Remove_internal to
More information about the llvm-commits
mailing list