diff options
author | Chris Lattner <sabre@nondot.org> | 2007-06-21 23:23:32 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-06-21 23:23:32 +0000 |
commit | 836e8f3f3916fd8e00bbd5a34f325130dcff9698 (patch) | |
tree | a93bccc0ca8fbb418f51fb565e01aadb142daa3d /llvm/lib/Support/SmallPtrSet.cpp | |
parent | 703de8fea882675e8b4b83ed77225b78b9aaa865 (diff) | |
download | llvm-836e8f3f3916fd8e00bbd5a34f325130dcff9698.zip llvm-836e8f3f3916fd8e00bbd5a34f325130dcff9698.tar.gz llvm-836e8f3f3916fd8e00bbd5a34f325130dcff9698.tar.bz2 |
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
llvm-svn: 37696
Diffstat (limited to 'llvm/lib/Support/SmallPtrSet.cpp')
-rw-r--r-- | llvm/lib/Support/SmallPtrSet.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/llvm/lib/Support/SmallPtrSet.cpp b/llvm/lib/Support/SmallPtrSet.cpp index 61fad5e..56c5e3d 100644 --- a/llvm/lib/Support/SmallPtrSet.cpp +++ b/llvm/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]; |