mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[ADT] Make DenseMap use allocate_buffer
This unlocks some goodies like sized deletion and gets the alignment right on platforms that chose to provide a lower default new alignment. llvm-svn: 371846
This commit is contained in:
parent
3bd19df6e5
commit
be6030386a
@ -748,7 +748,7 @@ public:
|
|||||||
|
|
||||||
~DenseMap() {
|
~DenseMap() {
|
||||||
this->destroyAll();
|
this->destroyAll();
|
||||||
operator delete(Buckets);
|
deallocate_buffer(Buckets, sizeof(BucketT) * NumBuckets, alignof(BucketT));
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(DenseMap& RHS) {
|
void swap(DenseMap& RHS) {
|
||||||
@ -768,7 +768,7 @@ public:
|
|||||||
|
|
||||||
DenseMap& operator=(DenseMap &&other) {
|
DenseMap& operator=(DenseMap &&other) {
|
||||||
this->destroyAll();
|
this->destroyAll();
|
||||||
operator delete(Buckets);
|
deallocate_buffer(Buckets, sizeof(BucketT) * NumBuckets, alignof(BucketT));
|
||||||
init(0);
|
init(0);
|
||||||
swap(other);
|
swap(other);
|
||||||
return *this;
|
return *this;
|
||||||
@ -776,7 +776,7 @@ public:
|
|||||||
|
|
||||||
void copyFrom(const DenseMap& other) {
|
void copyFrom(const DenseMap& other) {
|
||||||
this->destroyAll();
|
this->destroyAll();
|
||||||
operator delete(Buckets);
|
deallocate_buffer(Buckets, sizeof(BucketT) * NumBuckets, alignof(BucketT));
|
||||||
if (allocateBuckets(other.NumBuckets)) {
|
if (allocateBuckets(other.NumBuckets)) {
|
||||||
this->BaseT::copyFrom(other);
|
this->BaseT::copyFrom(other);
|
||||||
} else {
|
} else {
|
||||||
@ -809,10 +809,12 @@ public:
|
|||||||
this->moveFromOldBuckets(OldBuckets, OldBuckets+OldNumBuckets);
|
this->moveFromOldBuckets(OldBuckets, OldBuckets+OldNumBuckets);
|
||||||
|
|
||||||
// Free the old table.
|
// Free the old table.
|
||||||
operator delete(OldBuckets);
|
deallocate_buffer(OldBuckets, sizeof(BucketT) * OldNumBuckets,
|
||||||
|
alignof(BucketT));
|
||||||
}
|
}
|
||||||
|
|
||||||
void shrink_and_clear() {
|
void shrink_and_clear() {
|
||||||
|
unsigned OldNumBuckets = NumBuckets;
|
||||||
unsigned OldNumEntries = NumEntries;
|
unsigned OldNumEntries = NumEntries;
|
||||||
this->destroyAll();
|
this->destroyAll();
|
||||||
|
|
||||||
@ -825,7 +827,8 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator delete(Buckets);
|
deallocate_buffer(Buckets, sizeof(BucketT) * OldNumBuckets,
|
||||||
|
alignof(BucketT));
|
||||||
init(NewNumBuckets);
|
init(NewNumBuckets);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -861,7 +864,8 @@ private:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Buckets = static_cast<BucketT*>(operator new(sizeof(BucketT) * NumBuckets));
|
Buckets = static_cast<BucketT *>(
|
||||||
|
allocate_buffer(sizeof(BucketT) * NumBuckets, alignof(BucketT)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -1076,7 +1080,8 @@ public:
|
|||||||
this->moveFromOldBuckets(OldRep.Buckets, OldRep.Buckets+OldRep.NumBuckets);
|
this->moveFromOldBuckets(OldRep.Buckets, OldRep.Buckets+OldRep.NumBuckets);
|
||||||
|
|
||||||
// Free the old table.
|
// Free the old table.
|
||||||
operator delete(OldRep.Buckets);
|
deallocate_buffer(OldRep.Buckets, sizeof(BucketT) * OldRep.NumBuckets,
|
||||||
|
alignof(BucketT));
|
||||||
}
|
}
|
||||||
|
|
||||||
void shrink_and_clear() {
|
void shrink_and_clear() {
|
||||||
@ -1160,15 +1165,17 @@ private:
|
|||||||
if (Small)
|
if (Small)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
operator delete(getLargeRep()->Buckets);
|
deallocate_buffer(getLargeRep()->Buckets,
|
||||||
|
sizeof(BucketT) * getLargeRep()->NumBuckets,
|
||||||
|
alignof(BucketT));
|
||||||
getLargeRep()->~LargeRep();
|
getLargeRep()->~LargeRep();
|
||||||
}
|
}
|
||||||
|
|
||||||
LargeRep allocateBuckets(unsigned Num) {
|
LargeRep allocateBuckets(unsigned Num) {
|
||||||
assert(Num > InlineBuckets && "Must allocate more buckets than are inline");
|
assert(Num > InlineBuckets && "Must allocate more buckets than are inline");
|
||||||
LargeRep Rep = {
|
LargeRep Rep = {static_cast<BucketT *>(allocate_buffer(
|
||||||
static_cast<BucketT*>(operator new(sizeof(BucketT) * Num)), Num
|
sizeof(BucketT) * Num, alignof(BucketT))),
|
||||||
};
|
Num};
|
||||||
return Rep;
|
return Rep;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user