Skip to content

Commit

Permalink
Use reserveExtra in proxygen/lib/http/codec/compress/experimental/sim…
Browse files Browse the repository at this point in the history
…ulator/CompressionUtils.cpp

Summary:
This code contains an instance of:
```
container.reserve(container.size()+N)
```
If called repeatedly on the same container, performance will be bad. It's safer to use:
```
reserveExtra(container, N)
```

See [this post](https://fb.workplace.com/groups/638005567605797/posts/1066088434797506) for more details.

Reviewed By: r-barnes

Differential Revision: D48692107

fbshipit-source-id: 21e90d079bcbeeb54209a0276e0f45820de3319c
  • Loading branch information
marksantaniello authored and facebook-github-bot committed Sep 13, 2023
1 parent d523167 commit 7769b27
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/

#include "common/base/ReserveUtils.h"
#include <proxygen/lib/http/codec/compress/experimental/simulator/CompressionUtils.h>

#include <proxygen/lib/http/HeaderConstants.h>
Expand Down Expand Up @@ -111,7 +112,7 @@ std::vector<compress::Header> prepareMessageForCompression(
if (code == HTTP_HEADER_COOKIE) {
vector<folly::StringPiece> cookiePieces;
folly::split(';', value, cookiePieces);
cookies.reserve(cookies.size() + cookiePieces.size());
facebook::memory::reserveExtra(cookies, cookiePieces.size());
for (auto cookie : cookiePieces) {
cookies.push_back(ltrimWhitespace(cookie).str());
allHeaders.emplace_back(code, name, cookies.back());
Expand Down

0 comments on commit 7769b27

Please sign in to comment.