Optimize toJson() Performance
authorMilo Yip <miloyip@gmail.com>
Tue, 13 Sep 2016 18:24:35 +0000 (11:24 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Tue, 13 Sep 2016 18:38:29 +0000 (11:38 -0700)
Summary:
Removing string::reserve() which causes O(n^2) penalty.

Fixes #477
Closes https://github.com/facebook/folly/pull/478

Reviewed By: yfeldblum

Differential Revision: D3850509

Pulled By: Orvid

fbshipit-source-id: ecf44c35b2aedadc5385d23c325cacab1abfd02d

folly/json.cpp

index f4607efd88754069754c25589886c94a8f4061bb..105b1ca7ff9264574fdd1ee0c9fb024ece10fa0b 100644 (file)
@@ -693,7 +693,6 @@ void escapeString(
     return c < 10 ? c + '0' : c - 10 + 'a';
   };
 
     return c < 10 ? c + '0' : c - 10 + 'a';
   };
 
-  out.reserve(out.size() + input.size() + 2);
   out.push_back('\"');
 
   auto* p = reinterpret_cast<const unsigned char*>(input.begin());
   out.push_back('\"');
 
   auto* p = reinterpret_cast<const unsigned char*>(input.begin());