Skip to content

Commit b7a673c

Browse files
[ADT] Delegate among DenseMap constructors (NFC) (#168309)
This patch teaches DenseMap constructors to delegate to other DenseMap constructors where we can. The intent is for these constructors to build on top of a higher-level concept like the default-constructed instance instead of calling init on our own. This is part of the effort outlined in #168255.
1 parent 49d5bb0 commit b7a673c

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

llvm/include/llvm/ADT/DenseMap.h

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -754,18 +754,12 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
754754
init(NumElementsToReserve);
755755
}
756756

757-
DenseMap(const DenseMap &other) : BaseT() {
758-
init(0);
759-
this->copyFrom(other);
760-
}
757+
DenseMap(const DenseMap &other) : DenseMap() { this->copyFrom(other); }
761758

762-
DenseMap(DenseMap &&other) : BaseT() {
763-
init(0);
764-
this->swap(other);
765-
}
759+
DenseMap(DenseMap &&other) : DenseMap() { this->swap(other); }
766760

767-
template <typename InputIt> DenseMap(const InputIt &I, const InputIt &E) {
768-
init(std::distance(I, E));
761+
template <typename InputIt>
762+
DenseMap(const InputIt &I, const InputIt &E) : DenseMap(std::distance(I, E)) {
769763
this->insert(I, E);
770764
}
771765

@@ -908,19 +902,15 @@ class SmallDenseMap
908902
init(NumElementsToReserve);
909903
}
910904

911-
SmallDenseMap(const SmallDenseMap &other) : BaseT() {
912-
init(0);
905+
SmallDenseMap(const SmallDenseMap &other) : SmallDenseMap() {
913906
this->copyFrom(other);
914907
}
915908

916-
SmallDenseMap(SmallDenseMap &&other) : BaseT() {
917-
init(0);
918-
this->swap(other);
919-
}
909+
SmallDenseMap(SmallDenseMap &&other) : SmallDenseMap() { this->swap(other); }
920910

921911
template <typename InputIt>
922-
SmallDenseMap(const InputIt &I, const InputIt &E) {
923-
init(std::distance(I, E));
912+
SmallDenseMap(const InputIt &I, const InputIt &E)
913+
: SmallDenseMap(std::distance(I, E)) {
924914
this->insert(I, E);
925915
}
926916

0 commit comments

Comments
 (0)