[llvm-commits] [support] r40120 - /support/trunk/lib/Support/SmallPtrSet.cpp

Reid Spencer rspencer at reidspencer.com
Fri Jul 20 14:02:16 PDT 2007


Author: reid
Date: Fri Jul 20 16:02:15 2007
New Revision: 40120

URL: http://llvm.org/viewvc/llvm-project?rev=40120&view=rev
Log:
Migrate changes made in the llvm module, revisions 39958-40043, into the support
module version.

Modified:
    support/trunk/lib/Support/SmallPtrSet.cpp

Modified: support/trunk/lib/Support/SmallPtrSet.cpp
URL: http://llvm.org/viewvc/llvm-project/support/trunk/lib/Support/SmallPtrSet.cpp?rev=40120&r1=40119&r2=40120&view=diff

==============================================================================
--- support/trunk/lib/Support/SmallPtrSet.cpp (original)
+++ support/trunk/lib/Support/SmallPtrSet.cpp Fri Jul 20 16:02:15 2007
@@ -184,15 +184,18 @@
   if (isSmall() && RHS.isSmall())
     assert(CurArraySize == RHS.CurArraySize &&
            "Cannot assign sets with different small sizes");
-  NumElements = RHS.NumElements;
-  NumTombstones = RHS.NumTombstones;
-  
+           
   // If we're becoming small, prepare to insert into our stack space
-  if (RHS.isSmall())
+  if (RHS.isSmall()) {
+    if (!isSmall())
+      free(CurArray);
     CurArray = &SmallArray[0];
   // Otherwise, allocate new heap space (unless we were the same size)
-  else if (CurArraySize != RHS.CurArraySize) {
-    CurArray = (void**)realloc(CurArray, sizeof(void*)*(RHS.CurArraySize+1));
+  } else if (CurArraySize != RHS.CurArraySize) {
+    if (isSmall())
+      CurArray = (void**)malloc(sizeof(void*) * (RHS.CurArraySize+1));
+    else
+      CurArray = (void**)realloc(CurArray, sizeof(void*)*(RHS.CurArraySize+1));
     assert(CurArray && "Failed to allocate memory?");
   }
   
@@ -201,6 +204,9 @@
 
   // Copy over the contents from the other set
   memcpy(CurArray, RHS.CurArray, sizeof(void*)*(CurArraySize+1));
+  
+  NumElements = RHS.NumElements;
+  NumTombstones = RHS.NumTombstones;
 }
 
 SmallPtrSetImpl::~SmallPtrSetImpl() {





More information about the llvm-commits mailing list