Merge bitcoin/bitcoin#29606: refactor: Reserve memory for ToLower/ToUpper conversions

6f2f4a4d096a3b261258c8cdd96cca532988d1d3 Reserve memory for ToLower/ToUpper conversions (Lőrinc)

Pull request description:

  Similarly to https://github.com/bitcoin/bitcoin/pull/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 6f2f4a4d096a3b261258c8cdd96cca532988d1d3
  maflcko:
    lgtm ACK 6f2f4a4d096a3b261258c8cdd96cca532988d1d3
  achow101:
    ACK 6f2f4a4d096a3b261258c8cdd96cca532988d1d3
  Empact:
    Code Review ACK 6f2f4a4d09
  stickies-v:
    ACK 6f2f4a4d096a3b261258c8cdd96cca532988d1d3

Tree-SHA512: e3ba7af77decdc73272d804c94fef0b11028a85f3c0ea1ed6386672611b1c35fce151f02e64f5bb5acb5ba506aaa54577719b07925b9cc745143cf5c7e5eb262
This commit is contained in:
Ava Chow 2024-03-13 08:18:01 -04:00 committed by pasta
parent 045fa5f57e
commit d0e15d59f8
No known key found for this signature in database
GPG Key ID: E2F3D7916E722D38

View File

@ -476,6 +476,7 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out)
std::string ToLower(const std::string& str)
{
std::string r;
r.reserve(str.size());
for (auto ch : str) r += ToLower(ch);
return r;
}
@ -483,6 +484,7 @@ std::string ToLower(const std::string& str)
std::string ToUpper(const std::string& str)
{
std::string r;
r.reserve(str.size());
for (auto ch : str) r += ToUpper(ch);
return r;
}