Skip to content

Commit c38157b

Browse files
committed
Merge bitcoin/bitcoin#29606: refactor: Reserve memory for ToLower/ToUpper conversions
6f2f4a4 Reserve memory for ToLower/ToUpper conversions (Lőrinc) Pull request description: Similarly to bitcoin/bitcoin#29458, we're preallocating the result string based on the input string's length. The methods were already [covered by tests](https://github.com/bitcoin/bitcoin/blob/master/src/test/util_tests.cpp#L1250-L1276). ACKs for top commit: tdb3: ACK for 6f2f4a4 maflcko: lgtm ACK 6f2f4a4 achow101: ACK 6f2f4a4 Empact: Code Review ACK bitcoin/bitcoin@6f2f4a4 stickies-v: ACK 6f2f4a4 Tree-SHA512: e3ba7af77decdc73272d804c94fef0b11028a85f3c0ea1ed6386672611b1c35fce151f02e64f5bb5acb5ba506aaa54577719b07925b9cc745143cf5c7e5eb262
2 parents 264ca9d + 6f2f4a4 commit c38157b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/util/strencodings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,15 @@ bool ParseFixedPoint(std::string_view val, int decimals, int64_t *amount_out)
446446
std::string ToLower(std::string_view str)
447447
{
448448
std::string r;
449+
r.reserve(str.size());
449450
for (auto ch : str) r += ToLower(ch);
450451
return r;
451452
}
452453

453454
std::string ToUpper(std::string_view str)
454455
{
455456
std::string r;
457+
r.reserve(str.size());
456458
for (auto ch : str) r += ToUpper(ch);
457459
return r;
458460
}

0 commit comments

Comments
 (0)