diff options
author | Matthias Braun <matze@braunis.de> | 2016-01-28 04:49:11 +0000 |
---|---|---|
committer | Matthias Braun <matze@braunis.de> | 2016-01-28 04:49:11 +0000 |
commit | 924f080529d57f5b4a7e76347bc4e14a5dbaa328 (patch) | |
tree | 96650d825a35de89d1ece101f2e18bf09bd98fa5 /llvm/lib/Support/SmallPtrSet.cpp | |
parent | f67e5c79d70cd5e314d1567b6596bb62f06785d8 (diff) | |
download | bcm5719-llvm-924f080529d57f5b4a7e76347bc4e14a5dbaa328.tar.gz bcm5719-llvm-924f080529d57f5b4a7e76347bc4e14a5dbaa328.zip |
SmallPtrSet: Share some code between copy/move constructor/assignment operator
llvm-svn: 259018
Diffstat (limited to 'llvm/lib/Support/SmallPtrSet.cpp')
-rw-r--r-- | llvm/lib/Support/SmallPtrSet.cpp | 46 |
1 files changed, 13 insertions, 33 deletions
diff --git a/llvm/lib/Support/SmallPtrSet.cpp b/llvm/lib/Support/SmallPtrSet.cpp index 22274f5bbf9..3717f62150f 100644 --- a/llvm/lib/Support/SmallPtrSet.cpp +++ b/llvm/lib/Support/SmallPtrSet.cpp @@ -164,45 +164,17 @@ SmallPtrSetImplBase::SmallPtrSetImplBase(const void **SmallStorage, assert(CurArray && "Failed to allocate memory?"); } - // Copy over the new array size - CurArraySize = that.CurArraySize; - - // Copy over the contents from the other set - memcpy(CurArray, that.CurArray, sizeof(void*)*CurArraySize); - - NumElements = that.NumElements; - NumTombstones = that.NumTombstones; + // Copy over the that array. + CopyHelper(that); } SmallPtrSetImplBase::SmallPtrSetImplBase(const void **SmallStorage, unsigned SmallSize, SmallPtrSetImplBase &&that) { SmallArray = SmallStorage; - - // Copy over the basic members. - CurArraySize = that.CurArraySize; - NumElements = that.NumElements; - NumTombstones = that.NumTombstones; - - // When small, just copy into our small buffer. - if (that.isSmall()) { - CurArray = SmallArray; - memcpy(CurArray, that.CurArray, sizeof(void *) * CurArraySize); - } else { - // Otherwise, we steal the large memory allocation and no copy is needed. - CurArray = that.CurArray; - that.CurArray = that.SmallArray; - } - - // Make the "that" object small and empty. - that.CurArraySize = SmallSize; - assert(that.CurArray == that.SmallArray); - that.NumElements = 0; - that.NumTombstones = 0; + MoveHelper(SmallSize, std::move(that)); } -/// CopyFrom - implement operator= from a smallptrset that has the same pointer -/// type, but may have a different small size. void SmallPtrSetImplBase::CopyFrom(const SmallPtrSetImplBase &RHS) { assert(&RHS != this && "Self-copy should be handled by the caller."); @@ -229,6 +201,10 @@ void SmallPtrSetImplBase::CopyFrom(const SmallPtrSetImplBase &RHS) { assert(CurArray && "Failed to allocate memory?"); } + CopyHelper(RHS); +} + +void SmallPtrSetImplBase::CopyHelper(const SmallPtrSetImplBase &RHS) { // Copy over the new array size CurArraySize = RHS.CurArraySize; @@ -241,10 +217,14 @@ void SmallPtrSetImplBase::CopyFrom(const SmallPtrSetImplBase &RHS) { void SmallPtrSetImplBase::MoveFrom(unsigned SmallSize, SmallPtrSetImplBase &&RHS) { - assert(&RHS != this && "Self-move should be handled by the caller."); - if (!isSmall()) free(CurArray); + MoveHelper(SmallSize, std::move(RHS)); +} + +void SmallPtrSetImplBase::MoveHelper(unsigned SmallSize, + SmallPtrSetImplBase &&RHS) { + assert(&RHS != this && "Self-move should be handled by the caller."); if (RHS.isSmall()) { // Copy a small RHS rather than moving. |