summaryrefslogtreecommitdiff
path: root/lib/Support/SmallPtrSet.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-06-21 23:23:32 +0000
committerChris Lattner <sabre@nondot.org>2007-06-21 23:23:32 +0000
commit61766cae0b635f6a65d4491aa063c5fc12745566 (patch)
treeff4c787815f61cbe8524d85e56993e3a75ade422 /lib/Support/SmallPtrSet.cpp
parent25e681ac221e83a7ebead99b4d3d88f1b3ab49bd (diff)
downloadllvm-61766cae0b635f6a65d4491aa063c5fc12745566.tar.gz
llvm-61766cae0b635f6a65d4491aa063c5fc12745566.tar.bz2
llvm-61766cae0b635f6a65d4491aa063c5fc12745566.tar.xz
Two changes:
1. Make SmallPtrSet::erase faster in the small case by replacing a memmove with a pointer copy. 2. Fix a bug where the null terminator at the end of the array in the small case was not copied git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37696 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/SmallPtrSet.cpp')
-rw-r--r--lib/Support/SmallPtrSet.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/Support/SmallPtrSet.cpp b/lib/Support/SmallPtrSet.cpp
index 61fad5ea50..56c5e3d18a 100644
--- a/lib/Support/SmallPtrSet.cpp
+++ b/lib/Support/SmallPtrSet.cpp
@@ -54,9 +54,8 @@ bool SmallPtrSetImpl::erase(void *Ptr) {
for (void **APtr = SmallArray, **E = SmallArray+NumElements;
APtr != E; ++APtr)
if (*APtr == Ptr) {
- // If it is in the set, move everything over, replacing this element.
- memmove(APtr, APtr+1, sizeof(void*)*(E-APtr-1));
- // Clear the end element.
+ // If it is in the set, replace this element.
+ *APtr = E[-1];
E[-1] = getEmptyMarker();
--NumElements;
return true;
@@ -151,7 +150,9 @@ SmallPtrSetImpl::SmallPtrSetImpl(const SmallPtrSetImpl& that) {
if (that.isSmall()) {
CurArraySize = that.CurArraySize;
CurArray = &SmallArray[0];
- memcpy(CurArray, that.CurArray, sizeof(void*)*CurArraySize);
+ // Copy the entire contents of the array, including the -1's and the null
+ // terminator.
+ memcpy(CurArray, that.CurArray, sizeof(void*)*(CurArraySize+1));
} else {
CurArraySize = that.NumElements < 64 ? 128 : that.NumElements*2;
CurArray = new void*[CurArraySize+1];