Skip to content

Commit 0ede7ac

Browse files
[ADT] Use llvm::copy in SmallPtrSet.cpp (NFC) (llvm#153930)
This patch uses llvm::copy in combination with buckets() and small_buckets().
1 parent 6fc1deb commit 0ede7ac

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

llvm/include/llvm/ADT/SmallPtrSet.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ class SmallPtrSetImplBase : public DebugEpochBase {
160160
return make_range(CurArray, EndPointer());
161161
}
162162

163+
iterator_range<const void *const *> buckets() const {
164+
return make_range(CurArray, EndPointer());
165+
}
166+
163167
/// insert_imp - This returns true if the pointer was new to the set, false if
164168
/// it was already in the set. This is hidden from the client so that the
165169
/// derived class can check that the right type of pointer is passed in.

llvm/lib/Support/SmallPtrSet.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "llvm/ADT/SmallPtrSet.h"
1515
#include "llvm/ADT/DenseMapInfo.h"
16+
#include "llvm/ADT/STLExtras.h"
1617
#include "llvm/Support/MathExtras.h"
1718
#include "llvm/Support/MemAlloc.h"
1819
#include <algorithm>
@@ -190,7 +191,7 @@ void SmallPtrSetImplBase::copyHelper(const SmallPtrSetImplBase &RHS) {
190191
CurArraySize = RHS.CurArraySize;
191192

192193
// Copy over the contents from the other set
193-
std::copy(RHS.CurArray, RHS.EndPointer(), CurArray);
194+
llvm::copy(RHS.buckets(), CurArray);
194195

195196
NumEntries = RHS.NumEntries;
196197
NumTombstones = RHS.NumTombstones;
@@ -214,7 +215,7 @@ void SmallPtrSetImplBase::moveHelper(const void **SmallStorage,
214215
if (RHS.isSmall()) {
215216
// Copy a small RHS rather than moving.
216217
CurArray = SmallStorage;
217-
std::copy(RHS.CurArray, RHS.CurArray + RHS.NumEntries, CurArray);
218+
llvm::copy(RHS.small_buckets(), CurArray);
218219
} else {
219220
CurArray = RHS.CurArray;
220221
RHS.CurArray = RHSSmallStorage;
@@ -252,7 +253,7 @@ void SmallPtrSetImplBase::swap(const void **SmallStorage,
252253
// If only RHS is small, copy the small elements into LHS and move the pointer
253254
// from LHS to RHS.
254255
if (!this->isSmall() && RHS.isSmall()) {
255-
std::copy(RHS.CurArray, RHS.CurArray + RHS.NumEntries, SmallStorage);
256+
llvm::copy(RHS.small_buckets(), SmallStorage);
256257
std::swap(RHS.CurArraySize, this->CurArraySize);
257258
std::swap(this->NumEntries, RHS.NumEntries);
258259
std::swap(this->NumTombstones, RHS.NumTombstones);
@@ -266,8 +267,7 @@ void SmallPtrSetImplBase::swap(const void **SmallStorage,
266267
// If only LHS is small, copy the small elements into RHS and move the pointer
267268
// from RHS to LHS.
268269
if (this->isSmall() && !RHS.isSmall()) {
269-
std::copy(this->CurArray, this->CurArray + this->NumEntries,
270-
RHSSmallStorage);
270+
llvm::copy(this->small_buckets(), RHSSmallStorage);
271271
std::swap(RHS.CurArraySize, this->CurArraySize);
272272
std::swap(RHS.NumEntries, this->NumEntries);
273273
std::swap(RHS.NumTombstones, this->NumTombstones);

0 commit comments

Comments
 (0)