Commit ac06a309 authored by Giuseppe Ottaviano's avatar Giuseppe Ottaviano Committed by facebook-github-bot-1

Skip reallocation in shrink_to_fit for empty fbvector

Reviewed By: philippv

Differential Revision: D2696314

fb-gh-sync-id: 105de2d99bb9f5ac82310e37f9302022c103befc
parent 140c62d2
...@@ -966,6 +966,12 @@ public: ...@@ -966,6 +966,12 @@ public:
} }
void shrink_to_fit() noexcept { void shrink_to_fit() noexcept {
if (empty()) {
// Just skip reallocation.
*this = fbvector();
return;
}
auto const newCapacityBytes = folly::goodMallocSize(size() * sizeof(T)); auto const newCapacityBytes = folly::goodMallocSize(size() * sizeof(T));
auto const newCap = newCapacityBytes / sizeof(T); auto const newCap = newCapacityBytes / sizeof(T);
auto const oldCap = capacity(); auto const oldCap = capacity();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment