Use exponential growth in fbstring::append(size_type n, value_type c)
authorGiuseppe Ottaviano <ott@fb.com>
Fri, 27 May 2016 16:49:40 +0000 (09:49 -0700)
committerFacebook Github Bot 1 <facebook-github-bot-1-bot@fb.com>
Fri, 27 May 2016 16:55:35 +0000 (09:55 -0700)
Summary:
Contrary to the other `append` flavors, `fbstring::append(size_type n, value_type c)`
does not use exponential growth, which can trigger quadratic behavior.

Reviewed By: philippv

Differential Revision: D3357315

fbshipit-source-id: 2301ed1a9953544368663107113890a25c6621ae

folly/FBString.h

index 346d23c4247c3bc9ebdf654b8f16fb9a1a71f0f9..0c8273e5a19371b7f5db198e478ef45a31e53246 100644 (file)
@@ -1338,7 +1338,9 @@ public:
   }
 
   basic_fbstring& append(size_type n, value_type c) {
-    resize(size() + n, c);
+    Invariant checker(*this);
+    auto pData = store_.expand_noinit(n, /* expGrowth = */ true);
+    fbstring_detail::pod_fill(pData, pData + n, c);
     return *this;
   }