[llvm-commits] CVS: llvm/lib/Support/SmallPtrSet.cpp

Chris Lattner sabre at nondot.org
Thu Jun 21 16:23:54 PDT 2007



Changes in directory llvm/lib/Support:

SmallPtrSet.cpp updated: 1.6 -> 1.7
---
Log message:

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


---
Diffs of the changes:  (+5 -4)

 SmallPtrSet.cpp |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)


Index: llvm/lib/Support/SmallPtrSet.cpp
diff -u llvm/lib/Support/SmallPtrSet.cpp:1.6 llvm/lib/Support/SmallPtrSet.cpp:1.7
--- llvm/lib/Support/SmallPtrSet.cpp:1.6	Sat Apr 14 16:50:21 2007
+++ llvm/lib/Support/SmallPtrSet.cpp	Thu Jun 21 18:23:32 2007
@@ -54,9 +54,8 @@
     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 @@
   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];






More information about the llvm-commits mailing list