llvm.org GIT mirror llvm / 076e31e
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@371846 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 9 months ago
1 changed file(s) with 18 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
747747
748748 ~DenseMap() {
749749 this->destroyAll();
750 operator delete(Buckets);
750 deallocate_buffer(Buckets, sizeof(BucketT) * NumBuckets, alignof(BucketT));
751751 }
752752
753753 void swap(DenseMap& RHS) {
767767
768768 DenseMap& operator=(DenseMap &&other) {
769769 this->destroyAll();
770 operator delete(Buckets);
770 deallocate_buffer(Buckets, sizeof(BucketT) * NumBuckets, alignof(BucketT));
771771 init(0);
772772 swap(other);
773773 return *this;
775775
776776 void copyFrom(const DenseMap& other) {
777777 this->destroyAll();
778 operator delete(Buckets);
778 deallocate_buffer(Buckets, sizeof(BucketT) * NumBuckets, alignof(BucketT));
779779 if (allocateBuckets(other.NumBuckets)) {
780780 this->BaseT::copyFrom(other);
781781 } else {
808808 this->moveFromOldBuckets(OldBuckets, OldBuckets+OldNumBuckets);
809809
810810 // Free the old table.
811 operator delete(OldBuckets);
811 deallocate_buffer(OldBuckets, sizeof(BucketT) * OldNumBuckets,
812 alignof(BucketT));
812813 }
813814
814815 void shrink_and_clear() {
816 unsigned OldNumBuckets = NumBuckets;
815817 unsigned OldNumEntries = NumEntries;
816818 this->destroyAll();
817819
824826 return;
825827 }
826828
827 operator delete(Buckets);
829 deallocate_buffer(Buckets, sizeof(BucketT) * OldNumBuckets,
830 alignof(BucketT));
828831 init(NewNumBuckets);
829832 }
830833
860863 return false;
861864 }
862865
863 Buckets = static_cast*>(operator new(sizeof(BucketT) * NumBuckets));
866 Buckets = static_cast *>(
867 allocate_buffer(sizeof(BucketT) * NumBuckets, alignof(BucketT)));
864868 return true;
865869 }
866870 };
10751079 this->moveFromOldBuckets(OldRep.Buckets, OldRep.Buckets+OldRep.NumBuckets);
10761080
10771081 // Free the old table.
1078 operator delete(OldRep.Buckets);
1082 deallocate_buffer(OldRep.Buckets, sizeof(BucketT) * OldRep.NumBuckets,
1083 alignof(BucketT));
10791084 }
10801085
10811086 void shrink_and_clear() {
11591164 if (Small)
11601165 return;
11611166
1162 operator delete(getLargeRep()->Buckets);
1167 deallocate_buffer(getLargeRep()->Buckets,
1168 sizeof(BucketT) * getLargeRep()->NumBuckets,
1169 alignof(BucketT));
11631170 getLargeRep()->~LargeRep();
11641171 }
11651172
11661173 LargeRep allocateBuckets(unsigned Num) {
11671174 assert(Num > InlineBuckets && "Must allocate more buckets than are inline");
1168 LargeRep Rep = {
1169 static_cast(operator new(sizeof(BucketT) * Num)), Num
1170 };
1175 LargeRep Rep = {static_cast(allocate_buffer(
1176 sizeof(BucketT) * Num, alignof(BucketT))),
1177 Num};
11711178 return Rep;
11721179 }
11731180 };