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

Reid Spencer rspencer at reidspencer.com
Tue Jul 24 14:55:40 PDT 2007


All,

It would help me out a lot if you'd merge changes to lib/Support,
lib/System, include/llvm/Support and include/llvm/System into the
"support" module. I've been doing these as they come up but I might miss
some. 

In the near future, the directories just mentioned will be moved out of
the "llvm" module and into the "support" module. The only thing needing
to be finished for this to happen is ensuring the makefile system in
support can be used by llvm. In the mean time, please use the "svn
merge" command to apply your changes to the support module as well.

Thanks,

Reid.

On Tue, 2007-07-24 at 21:31 +0000, Owen Anderson wrote:
> Author: resistor
> Date: Tue Jul 24 16:31:23 2007
> New Revision: 40474
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=40474&view=rev
> Log:
> Make the copy constructor of SmallPtrSet much faster.
> 
> Modified:
>     llvm/trunk/lib/Support/SmallPtrSet.cpp
> 
> Modified: llvm/trunk/lib/Support/SmallPtrSet.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SmallPtrSet.cpp?rev=40474&r1=40473&r2=40474&view=diff
> 
> ==============================================================================
> --- llvm/trunk/lib/Support/SmallPtrSet.cpp (original)
> +++ llvm/trunk/lib/Support/SmallPtrSet.cpp Tue Jul 24 16:31:23 2007
> @@ -149,33 +149,23 @@
>  }
>  
>  SmallPtrSetImpl::SmallPtrSetImpl(const SmallPtrSetImpl& that) {
> -  NumElements = that.NumElements;
> -  NumTombstones = 0;
> +  // If we're becoming small, prepare to insert into our stack space
>    if (that.isSmall()) {
> -    CurArraySize = that.CurArraySize;
>      CurArray = &SmallArray[0];
> -    // Copy the entire contents of the array, including the -1's and the null
> -    // terminator.
> -    memcpy(CurArray, that.CurArray, sizeof(void*)*(CurArraySize+1));
> +  // Otherwise, allocate new heap space (unless we were the same size)
>    } else {
> -    CurArraySize = that.NumElements < 64 ? 128 : that.CurArraySize*2;
> -    CurArray = (void**)malloc(sizeof(void*) * (CurArraySize+1));
> +    CurArray = (void**)malloc(sizeof(void*) * (that.CurArraySize+1));
>      assert(CurArray && "Failed to allocate memory?");
> -    memset(CurArray, -1, CurArraySize*sizeof(void*));
> -    
> -    // The end pointer, always valid, is set to a valid element to help the
> -    // iterator.
> -    CurArray[CurArraySize] = 0;
> -
> -    // Copy over all valid entries.
> -    for (void **BucketPtr = that.CurArray, **E = that.CurArray+that.CurArraySize;
> -         BucketPtr != E; ++BucketPtr) {
> -      // Copy over the element if it is valid.
> -      void *Elt = *BucketPtr;
> -      if (Elt != getTombstoneMarker() && Elt != getEmptyMarker())
> -        *const_cast<void**>(FindBucketFor(Elt)) = Elt;
> -    }
>    }
> +  
> +  // Copy over the new array size
> +  CurArraySize = that.CurArraySize;
> +
> +  // Copy over the contents from the other set
> +  memcpy(CurArray, that.CurArray, sizeof(void*)*(CurArraySize+1));
> +  
> +  NumElements = that.NumElements;
> +  NumTombstones = that.NumTombstones;
>  }
>  
>  /// CopyFrom - implement operator= from a smallptrset that has the same pointer
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list