[llvm] [ADT] Delegate among DenseMap constructors (NFC) (PR #168309)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 16 18:47:38 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/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.
>From c067902d1a4839b7edbbb937332cc13769a0a184 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 16 Nov 2025 18:03:08 -0800
Subject: [PATCH] [ADT] Delegate among DenseMap constructors (NFC)
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.
---
llvm/include/llvm/ADT/DenseMap.h | 26 ++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index 86592f12ce62c..fa87b812f9bf8 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -751,18 +751,12 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
init(NumElementsToReserve);
}
- DenseMap(const DenseMap &other) : BaseT() {
- init(0);
- this->copyFrom(other);
- }
+ DenseMap(const DenseMap &other) : DenseMap() { this->copyFrom(other); }
- DenseMap(DenseMap &&other) : BaseT() {
- init(0);
- this->swap(other);
- }
+ DenseMap(DenseMap &&other) : DenseMap() { this->swap(other); }
- template <typename InputIt> DenseMap(const InputIt &I, const InputIt &E) {
- init(std::distance(I, E));
+ template <typename InputIt>
+ DenseMap(const InputIt &I, const InputIt &E) : DenseMap(std::distance(I, E)) {
this->insert(I, E);
}
@@ -901,19 +895,15 @@ class SmallDenseMap
init(NumElementsToReserve);
}
- SmallDenseMap(const SmallDenseMap &other) : BaseT() {
- init(0);
+ SmallDenseMap(const SmallDenseMap &other) : SmallDenseMap() {
this->copyFrom(other);
}
- SmallDenseMap(SmallDenseMap &&other) : BaseT() {
- init(0);
- this->swap(other);
- }
+ SmallDenseMap(SmallDenseMap &&other) : SmallDenseMap() { this->swap(other); }
template <typename InputIt>
- SmallDenseMap(const InputIt &I, const InputIt &E) {
- init(std::distance(I, E));
+ SmallDenseMap(const InputIt &I, const InputIt &E)
+ : SmallDenseMap(std::distance(I, E)) {
this->insert(I, E);
}
More information about the llvm-commits
mailing list