From b4fc2b5583101141ead49dfc8739d5aa7c335010 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 30 Oct 2015 12:37:50 -0400 Subject: [PATCH] JSON: Added std::string::reserve to compensate for growth --- src/JSON.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/JSON.cpp b/src/JSON.cpp index 353fca868..d39bea37a 100644 --- a/src/JSON.cpp +++ b/src/JSON.cpp @@ -377,6 +377,7 @@ json::value* json::parse (const std::string& input) std::string json::encode (const std::string& input) { std::string output; + output.reserve ((input.size () * 6) / 5); // 20% increase. for (auto& i : input) { @@ -405,6 +406,8 @@ std::string json::encode (const std::string& input) std::string json::decode (const std::string& input) { std::string output; + output.reserve (input.size ()); // Same size. + size_t pos = 0; while (pos < input.length ())