Skip to content

Commit c2fe408

Browse files
[ADT] Use list-initialization for returning pairs (#160238)
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/.
1 parent 99618de commit c2fe408

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

llvm/include/llvm/ADT/DenseMapInfo.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,11 @@ struct DenseMapInfo<std::pair<T, U>> {
139139
using SecondInfo = DenseMapInfo<U>;
140140

141141
static constexpr Pair getEmptyKey() {
142-
return std::make_pair(FirstInfo::getEmptyKey(),
143-
SecondInfo::getEmptyKey());
142+
return {FirstInfo::getEmptyKey(), SecondInfo::getEmptyKey()};
144143
}
145144

146145
static constexpr Pair getTombstoneKey() {
147-
return std::make_pair(FirstInfo::getTombstoneKey(),
148-
SecondInfo::getTombstoneKey());
146+
return {FirstInfo::getTombstoneKey(), SecondInfo::getTombstoneKey()};
149147
}
150148

151149
static unsigned getHashValue(const Pair& PairVal) {

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ class indexed_accessor_range
13711371
offset_base(const std::pair<BaseT, ptrdiff_t> &base, ptrdiff_t index) {
13721372
// We encode the internal base as a pair of the derived base and a start
13731373
// index into the derived base.
1374-
return std::make_pair(base.first, base.second + index);
1374+
return {base.first, base.second + index};
13751375
}
13761376
/// See `detail::indexed_accessor_range_base` for details.
13771377
static ReferenceT

llvm/include/llvm/ADT/SparseMultiSet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class SparseMultiSet {
400400
RangePair equal_range(const KeyT &K) {
401401
iterator B = find(K);
402402
iterator E = iterator(this, SMSNode::INVALID, B.SparseIdx);
403-
return std::make_pair(B, E);
403+
return {B, E};
404404
}
405405

406406
/// Insert a new element at the tail of the subset list. Returns an iterator

llvm/include/llvm/ADT/StringRef.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,8 @@ namespace llvm {
717717
split(StringRef Separator) const {
718718
size_t Idx = find(Separator);
719719
if (Idx == npos)
720-
return std::make_pair(*this, StringRef());
721-
return std::make_pair(slice(0, Idx), substr(Idx + Separator.size()));
720+
return {*this, StringRef()};
721+
return {slice(0, Idx), substr(Idx + Separator.size())};
722722
}
723723

724724
/// Split into two substrings around the last occurrence of a separator
@@ -735,8 +735,8 @@ namespace llvm {
735735
rsplit(StringRef Separator) const {
736736
size_t Idx = rfind(Separator);
737737
if (Idx == npos)
738-
return std::make_pair(*this, StringRef());
739-
return std::make_pair(slice(0, Idx), substr(Idx + Separator.size()));
738+
return {*this, StringRef()};
739+
return {slice(0, Idx), substr(Idx + Separator.size())};
740740
}
741741

742742
/// Split into substrings around the occurrences of a separator string.

0 commit comments

Comments
 (0)