Skip to content

Commit 78238dc

Browse files
[Support] Use list-initialization for returning pairs (#160645)
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 Support/.
1 parent 0fd341c commit 78238dc

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

llvm/lib/Support/ARMWinEH.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ std::pair<uint16_t, uint32_t> SavedRegisterMask(const RuntimeFunction &RF,
4141
GPRMask |= (((1 << ((RF.StackAdjust() & 0x3) + 1)) - 1)
4242
<< (~RF.StackAdjust() & 0x3));
4343

44-
return std::make_pair(GPRMask, VFPMask);
44+
return {GPRMask, VFPMask};
4545
}
4646
} // namespace WinEH
4747
} // namespace ARM

llvm/lib/Support/BinaryStreamReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,5 @@ BinaryStreamReader::split(uint64_t Off) const {
174174
First = First.keep_front(Off);
175175
BinaryStreamReader W1{First};
176176
BinaryStreamReader W2{Second};
177-
return std::make_pair(W1, W2);
177+
return {W1, W2};
178178
}

llvm/lib/Support/BinaryStreamWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ BinaryStreamWriter::split(uint64_t Off) const {
8989
First = First.keep_front(Off);
9090
BinaryStreamWriter W1{First};
9191
BinaryStreamWriter W2{Second};
92-
return std::make_pair(W1, W2);
92+
return {W1, W2};
9393
}
9494

9595
Error BinaryStreamWriter::padToAlignment(uint32_t Align) {

llvm/lib/Support/YAMLParser.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,52 +59,52 @@ using EncodingInfo = std::pair<UnicodeEncodingForm, unsigned>;
5959
/// and how long the byte order mark is if one exists.
6060
static EncodingInfo getUnicodeEncoding(StringRef Input) {
6161
if (Input.empty())
62-
return std::make_pair(UEF_Unknown, 0);
62+
return {UEF_Unknown, 0};
6363

6464
switch (uint8_t(Input[0])) {
6565
case 0x00:
6666
if (Input.size() >= 4) {
6767
if ( Input[1] == 0
6868
&& uint8_t(Input[2]) == 0xFE
6969
&& uint8_t(Input[3]) == 0xFF)
70-
return std::make_pair(UEF_UTF32_BE, 4);
70+
return {UEF_UTF32_BE, 4};
7171
if (Input[1] == 0 && Input[2] == 0 && Input[3] != 0)
72-
return std::make_pair(UEF_UTF32_BE, 0);
72+
return {UEF_UTF32_BE, 0};
7373
}
7474

7575
if (Input.size() >= 2 && Input[1] != 0)
76-
return std::make_pair(UEF_UTF16_BE, 0);
77-
return std::make_pair(UEF_Unknown, 0);
76+
return {UEF_UTF16_BE, 0};
77+
return {UEF_Unknown, 0};
7878
case 0xFF:
7979
if ( Input.size() >= 4
8080
&& uint8_t(Input[1]) == 0xFE
8181
&& Input[2] == 0
8282
&& Input[3] == 0)
83-
return std::make_pair(UEF_UTF32_LE, 4);
83+
return {UEF_UTF32_LE, 4};
8484

8585
if (Input.size() >= 2 && uint8_t(Input[1]) == 0xFE)
86-
return std::make_pair(UEF_UTF16_LE, 2);
87-
return std::make_pair(UEF_Unknown, 0);
86+
return {UEF_UTF16_LE, 2};
87+
return {UEF_Unknown, 0};
8888
case 0xFE:
8989
if (Input.size() >= 2 && uint8_t(Input[1]) == 0xFF)
90-
return std::make_pair(UEF_UTF16_BE, 2);
91-
return std::make_pair(UEF_Unknown, 0);
90+
return {UEF_UTF16_BE, 2};
91+
return {UEF_Unknown, 0};
9292
case 0xEF:
9393
if ( Input.size() >= 3
9494
&& uint8_t(Input[1]) == 0xBB
9595
&& uint8_t(Input[2]) == 0xBF)
96-
return std::make_pair(UEF_UTF8, 3);
97-
return std::make_pair(UEF_Unknown, 0);
96+
return {UEF_UTF8, 3};
97+
return {UEF_Unknown, 0};
9898
}
9999

100100
// It could still be utf-32 or utf-16.
101101
if (Input.size() >= 4 && Input[1] == 0 && Input[2] == 0 && Input[3] == 0)
102-
return std::make_pair(UEF_UTF32_LE, 0);
102+
return {UEF_UTF32_LE, 0};
103103

104104
if (Input.size() >= 2 && Input[1] == 0)
105-
return std::make_pair(UEF_UTF16_LE, 0);
105+
return {UEF_UTF16_LE, 0};
106106

107-
return std::make_pair(UEF_UTF8, 0);
107+
return {UEF_UTF8, 0};
108108
}
109109

110110
/// Pin the vtables to this file.
@@ -199,7 +199,7 @@ static UTF8Decoded decodeUTF8(StringRef Range) {
199199
// 1 byte: [0x00, 0x7f]
200200
// Bit pattern: 0xxxxxxx
201201
if (Position < End && (*Position & 0x80) == 0) {
202-
return std::make_pair(*Position, 1);
202+
return {*Position, 1};
203203
}
204204
// 2 bytes: [0x80, 0x7ff]
205205
// Bit pattern: 110xxxxx 10xxxxxx
@@ -208,7 +208,7 @@ static UTF8Decoded decodeUTF8(StringRef Range) {
208208
uint32_t codepoint = ((*Position & 0x1F) << 6) |
209209
(*(Position + 1) & 0x3F);
210210
if (codepoint >= 0x80)
211-
return std::make_pair(codepoint, 2);
211+
return {codepoint, 2};
212212
}
213213
// 3 bytes: [0x8000, 0xffff]
214214
// Bit pattern: 1110xxxx 10xxxxxx 10xxxxxx
@@ -222,7 +222,7 @@ static UTF8Decoded decodeUTF8(StringRef Range) {
222222
// they are high / low surrogate halves used by UTF-16.
223223
if (codepoint >= 0x800 &&
224224
(codepoint < 0xD800 || codepoint > 0xDFFF))
225-
return std::make_pair(codepoint, 3);
225+
return {codepoint, 3};
226226
}
227227
// 4 bytes: [0x10000, 0x10FFFF]
228228
// Bit pattern: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
@@ -235,9 +235,9 @@ static UTF8Decoded decodeUTF8(StringRef Range) {
235235
((*(Position + 2) & 0x3F) << 6) |
236236
(*(Position + 3) & 0x3F);
237237
if (codepoint >= 0x10000 && codepoint <= 0x10FFFF)
238-
return std::make_pair(codepoint, 4);
238+
return {codepoint, 4};
239239
}
240-
return std::make_pair(0, 0);
240+
return {0, 0};
241241
}
242242

243243
namespace llvm {

0 commit comments

Comments
 (0)