@@ -28,7 +28,7 @@ void SmallPtrSetImplBase::shrink_and_clear() {
2828 // Reduce the number of buckets.
2929 unsigned Size = size ();
3030 CurArraySize = Size > 16 ? 1 << (Log2_32_Ceil (Size) + 1 ) : 32 ;
31- NumNonEmpty = NumTombstones = 0 ;
31+ NumEntries = NumTombstones = 0 ;
3232
3333 // Install the new array. Clear all the buckets to empty.
3434 CurArray = (const void **)safe_malloc (sizeof (void *) * CurArraySize);
@@ -41,7 +41,8 @@ SmallPtrSetImplBase::insert_imp_big(const void *Ptr) {
4141 if (LLVM_UNLIKELY (size () * 4 >= CurArraySize * 3 )) {
4242 // If more than 3/4 of the array is full, grow.
4343 Grow (CurArraySize < 64 ? 128 : CurArraySize * 2 );
44- } else if (LLVM_UNLIKELY (CurArraySize - NumNonEmpty < CurArraySize / 8 )) {
44+ } else if (LLVM_UNLIKELY (CurArraySize - NumEntries - NumTombstones <
45+ CurArraySize / 8 )) {
4546 // If fewer of 1/8 of the array is empty (meaning that many are filled with
4647 // tombstones), rehash.
4748 Grow (CurArraySize);
@@ -55,8 +56,7 @@ SmallPtrSetImplBase::insert_imp_big(const void *Ptr) {
5556 // Otherwise, insert it!
5657 if (*Bucket == getTombstoneMarker ())
5758 --NumTombstones;
58- else
59- ++NumNonEmpty; // Track density.
59+ ++NumEntries;
6060 *Bucket = Ptr;
6161 incrementEpoch ();
6262 return std::make_pair (Bucket, true );
@@ -130,7 +130,6 @@ void SmallPtrSetImplBase::Grow(unsigned NewSize) {
130130
131131 if (!WasSmall)
132132 free (OldBuckets.begin ());
133- NumNonEmpty -= NumTombstones;
134133 NumTombstones = 0 ;
135134 IsSmall = false ;
136135}
@@ -193,7 +192,7 @@ void SmallPtrSetImplBase::copyHelper(const SmallPtrSetImplBase &RHS) {
193192 // Copy over the contents from the other set
194193 std::copy (RHS.CurArray , RHS.EndPointer (), CurArray);
195194
196- NumNonEmpty = RHS.NumNonEmpty ;
195+ NumEntries = RHS.NumEntries ;
197196 NumTombstones = RHS.NumTombstones ;
198197}
199198
@@ -215,21 +214,21 @@ void SmallPtrSetImplBase::moveHelper(const void **SmallStorage,
215214 if (RHS.isSmall ()) {
216215 // Copy a small RHS rather than moving.
217216 CurArray = SmallStorage;
218- std::copy (RHS.CurArray , RHS.CurArray + RHS.NumNonEmpty , CurArray);
217+ std::copy (RHS.CurArray , RHS.CurArray + RHS.NumEntries , CurArray);
219218 } else {
220219 CurArray = RHS.CurArray ;
221220 RHS.CurArray = RHSSmallStorage;
222221 }
223222
224223 // Copy the rest of the trivial members.
225224 CurArraySize = RHS.CurArraySize ;
226- NumNonEmpty = RHS.NumNonEmpty ;
225+ NumEntries = RHS.NumEntries ;
227226 NumTombstones = RHS.NumTombstones ;
228227 IsSmall = RHS.IsSmall ;
229228
230229 // Make the RHS small and empty.
231230 RHS.CurArraySize = SmallSize;
232- RHS.NumNonEmpty = 0 ;
231+ RHS.NumEntries = 0 ;
233232 RHS.NumTombstones = 0 ;
234233 RHS.IsSmall = true ;
235234}
@@ -243,7 +242,7 @@ void SmallPtrSetImplBase::swap(const void **SmallStorage,
243242 if (!this ->isSmall () && !RHS.isSmall ()) {
244243 std::swap (this ->CurArray , RHS.CurArray );
245244 std::swap (this ->CurArraySize , RHS.CurArraySize );
246- std::swap (this ->NumNonEmpty , RHS.NumNonEmpty );
245+ std::swap (this ->NumEntries , RHS.NumEntries );
247246 std::swap (this ->NumTombstones , RHS.NumTombstones );
248247 return ;
249248 }
@@ -253,9 +252,9 @@ void SmallPtrSetImplBase::swap(const void **SmallStorage,
253252 // If only RHS is small, copy the small elements into LHS and move the pointer
254253 // from LHS to RHS.
255254 if (!this ->isSmall () && RHS.isSmall ()) {
256- std::copy (RHS.CurArray , RHS.CurArray + RHS.NumNonEmpty , SmallStorage);
255+ std::copy (RHS.CurArray , RHS.CurArray + RHS.NumEntries , SmallStorage);
257256 std::swap (RHS.CurArraySize , this ->CurArraySize );
258- std::swap (this ->NumNonEmpty , RHS.NumNonEmpty );
257+ std::swap (this ->NumEntries , RHS.NumEntries );
259258 std::swap (this ->NumTombstones , RHS.NumTombstones );
260259 RHS.CurArray = this ->CurArray ;
261260 RHS.IsSmall = false ;
@@ -267,10 +266,10 @@ void SmallPtrSetImplBase::swap(const void **SmallStorage,
267266 // If only LHS is small, copy the small elements into RHS and move the pointer
268267 // from RHS to LHS.
269268 if (this ->isSmall () && !RHS.isSmall ()) {
270- std::copy (this ->CurArray , this ->CurArray + this ->NumNonEmpty ,
269+ std::copy (this ->CurArray , this ->CurArray + this ->NumEntries ,
271270 RHSSmallStorage);
272271 std::swap (RHS.CurArraySize , this ->CurArraySize );
273- std::swap (RHS.NumNonEmpty , this ->NumNonEmpty );
272+ std::swap (RHS.NumEntries , this ->NumEntries );
274273 std::swap (RHS.NumTombstones , this ->NumTombstones );
275274 this ->CurArray = RHS.CurArray ;
276275 this ->IsSmall = false ;
@@ -281,16 +280,16 @@ void SmallPtrSetImplBase::swap(const void **SmallStorage,
281280
282281 // Both a small, just swap the small elements.
283282 assert (this ->isSmall () && RHS.isSmall ());
284- unsigned MinNonEmpty = std::min (this ->NumNonEmpty , RHS.NumNonEmpty );
285- std::swap_ranges (this ->CurArray , this ->CurArray + MinNonEmpty , RHS.CurArray );
286- if (this ->NumNonEmpty > MinNonEmpty ) {
287- std::copy (this ->CurArray + MinNonEmpty , this ->CurArray + this ->NumNonEmpty ,
288- RHS.CurArray + MinNonEmpty );
283+ unsigned MinEntries = std::min (this ->NumEntries , RHS.NumEntries );
284+ std::swap_ranges (this ->CurArray , this ->CurArray + MinEntries , RHS.CurArray );
285+ if (this ->NumEntries > MinEntries ) {
286+ std::copy (this ->CurArray + MinEntries , this ->CurArray + this ->NumEntries ,
287+ RHS.CurArray + MinEntries );
289288 } else {
290- std::copy (RHS.CurArray + MinNonEmpty , RHS.CurArray + RHS.NumNonEmpty ,
291- this ->CurArray + MinNonEmpty );
289+ std::copy (RHS.CurArray + MinEntries , RHS.CurArray + RHS.NumEntries ,
290+ this ->CurArray + MinEntries );
292291 }
293292 assert (this ->CurArraySize == RHS.CurArraySize );
294- std::swap (this ->NumNonEmpty , RHS.NumNonEmpty );
293+ std::swap (this ->NumEntries , RHS.NumEntries );
295294 std::swap (this ->NumTombstones , RHS.NumTombstones );
296295}
0 commit comments