[llvm] [ADT] Use list-initialization for returning pairs (PR #160238)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 22 22:45:25 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
In C++17 and later, "return {A, B};" guarantees copy elision for a
std::pair return type, ensuring the object is constructed directly in
the return slot. This patch updates those instances under ADT/.
---
Full diff: https://github.com/llvm/llvm-project/pull/160238.diff
4 Files Affected:
- (modified) llvm/include/llvm/ADT/DenseMapInfo.h (+2-4)
- (modified) llvm/include/llvm/ADT/STLExtras.h (+1-1)
- (modified) llvm/include/llvm/ADT/SparseMultiSet.h (+1-1)
- (modified) llvm/include/llvm/ADT/StringRef.h (+4-4)
``````````diff
diff --git a/llvm/include/llvm/ADT/DenseMapInfo.h b/llvm/include/llvm/ADT/DenseMapInfo.h
index 57a8674e35015..f24aeb4371e7f 100644
--- a/llvm/include/llvm/ADT/DenseMapInfo.h
+++ b/llvm/include/llvm/ADT/DenseMapInfo.h
@@ -139,13 +139,11 @@ struct DenseMapInfo<std::pair<T, U>> {
using SecondInfo = DenseMapInfo<U>;
static constexpr Pair getEmptyKey() {
- return std::make_pair(FirstInfo::getEmptyKey(),
- SecondInfo::getEmptyKey());
+ return {FirstInfo::getEmptyKey(), SecondInfo::getEmptyKey()};
}
static constexpr Pair getTombstoneKey() {
- return std::make_pair(FirstInfo::getTombstoneKey(),
- SecondInfo::getTombstoneKey());
+ return {FirstInfo::getTombstoneKey(), SecondInfo::getTombstoneKey()};
}
static unsigned getHashValue(const Pair& PairVal) {
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 4e7e42e9f4a5f..4a91b061dd3b7 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1371,7 +1371,7 @@ class indexed_accessor_range
offset_base(const std::pair<BaseT, ptrdiff_t> &base, ptrdiff_t index) {
// We encode the internal base as a pair of the derived base and a start
// index into the derived base.
- return std::make_pair(base.first, base.second + index);
+ return {base.first, base.second + index};
}
/// See `detail::indexed_accessor_range_base` for details.
static ReferenceT
diff --git a/llvm/include/llvm/ADT/SparseMultiSet.h b/llvm/include/llvm/ADT/SparseMultiSet.h
index cf7603158b28b..0aa7edbcea673 100644
--- a/llvm/include/llvm/ADT/SparseMultiSet.h
+++ b/llvm/include/llvm/ADT/SparseMultiSet.h
@@ -400,7 +400,7 @@ class SparseMultiSet {
RangePair equal_range(const KeyT &K) {
iterator B = find(K);
iterator E = iterator(this, SMSNode::INVALID, B.SparseIdx);
- return std::make_pair(B, E);
+ return {B, E};
}
/// Insert a new element at the tail of the subset list. Returns an iterator
diff --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h
index 49a52fbe1a6f7..7aee2aa67ddec 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -717,8 +717,8 @@ namespace llvm {
split(StringRef Separator) const {
size_t Idx = find(Separator);
if (Idx == npos)
- return std::make_pair(*this, StringRef());
- return std::make_pair(slice(0, Idx), substr(Idx + Separator.size()));
+ return {*this, StringRef()};
+ return {slice(0, Idx), substr(Idx + Separator.size())};
}
/// Split into two substrings around the last occurrence of a separator
@@ -735,8 +735,8 @@ namespace llvm {
rsplit(StringRef Separator) const {
size_t Idx = rfind(Separator);
if (Idx == npos)
- return std::make_pair(*this, StringRef());
- return std::make_pair(slice(0, Idx), substr(Idx + Separator.size()));
+ return {*this, StringRef()};
+ return {slice(0, Idx), substr(Idx + Separator.size())};
}
/// Split into substrings around the occurrences of a separator string.
``````````
</details>
https://github.com/llvm/llvm-project/pull/160238
More information about the llvm-commits
mailing list