1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 02:21:16 +02:00

Merge pull request #12025 from NaN-git/strlen

optimize string concat
This commit is contained in:
Eelco Dolstra 2024-12-09 13:02:16 +01:00 committed by GitHub
commit 3081e7ce90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -338,7 +338,9 @@ std::string showBytes(uint64_t bytes);
*/
inline std::string operator + (const std::string & s1, std::string_view s2)
{
auto s = s1;
std::string s;
s.reserve(s1.size() + s2.size());
s.append(s1);
s.append(s2);
return s;
}
@ -351,10 +353,11 @@ inline std::string operator + (std::string && s, std::string_view s2)
inline std::string operator + (std::string_view s1, const char * s2)
{
auto s2Size = strlen(s2);
std::string s;
s.reserve(s1.size() + strlen(s2));
s.reserve(s1.size() + s2Size);
s.append(s1);
s.append(s2);
s.append(s2, s2Size);
return s;
}