1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-23 17:31:08 +01:00

Fix reserve pitfall in printString

Remove the per-call reserve() inside printString to avoid linear-growth reallocations when called in loops (e.g. printStrings). Derivation::unparse already pre-reserves a large buffer, so this remains efficient while preserving amortized growth behavior when the initial estimate is exceeded.
This commit is contained in:
Kamil Monicz 2025-12-19 01:03:30 +00:00
parent 188cb798ad
commit 66c867395f
No known key found for this signature in database
GPG key ID: F9FB19F1C1DC9C23

View file

@ -523,7 +523,6 @@ Derivation parseDerivation(
*/ */
static void printString(std::string & res, std::string_view s) static void printString(std::string & res, std::string_view s)
{ {
res.reserve(res.size() + s.size() * 2 + 2);
res += '"'; res += '"';
static constexpr auto chunkSize = 1024; static constexpr auto chunkSize = 1024;
std::array<char, 2 * chunkSize + 2> buffer; std::array<char, 2 * chunkSize + 2> buffer;