mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
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
This commit is contained in:
@@ -54,9 +54,8 @@ bool SmallPtrSetImpl::erase(void *Ptr) {
|
|||||||
for (void **APtr = SmallArray, **E = SmallArray+NumElements;
|
for (void **APtr = SmallArray, **E = SmallArray+NumElements;
|
||||||
APtr != E; ++APtr)
|
APtr != E; ++APtr)
|
||||||
if (*APtr == Ptr) {
|
if (*APtr == Ptr) {
|
||||||
// If it is in the set, move everything over, replacing this element.
|
// If it is in the set, replace this element.
|
||||||
memmove(APtr, APtr+1, sizeof(void*)*(E-APtr-1));
|
*APtr = E[-1];
|
||||||
// Clear the end element.
|
|
||||||
E[-1] = getEmptyMarker();
|
E[-1] = getEmptyMarker();
|
||||||
--NumElements;
|
--NumElements;
|
||||||
return true;
|
return true;
|
||||||
@@ -151,7 +150,9 @@ SmallPtrSetImpl::SmallPtrSetImpl(const SmallPtrSetImpl& that) {
|
|||||||
if (that.isSmall()) {
|
if (that.isSmall()) {
|
||||||
CurArraySize = that.CurArraySize;
|
CurArraySize = that.CurArraySize;
|
||||||
CurArray = &SmallArray[0];
|
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 {
|
} else {
|
||||||
CurArraySize = that.NumElements < 64 ? 128 : that.NumElements*2;
|
CurArraySize = that.NumElements < 64 ? 128 : that.NumElements*2;
|
||||||
CurArray = new void*[CurArraySize+1];
|
CurArray = new void*[CurArraySize+1];
|
||||||
|
Reference in New Issue
Block a user