From ac06a3093239f271ec81255ed8ad6c48b85e8f16 Mon Sep 17 00:00:00 2001 From: Giuseppe Ottaviano Date: Wed, 25 Nov 2015 13:39:14 -0800 Subject: [PATCH] Skip reallocation in shrink_to_fit for empty fbvector Reviewed By: philippv Differential Revision: D2696314 fb-gh-sync-id: 105de2d99bb9f5ac82310e37f9302022c103befc --- folly/FBVector.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/folly/FBVector.h b/folly/FBVector.h index 22d76034..c773a7f9 100644 --- a/folly/FBVector.h +++ b/folly/FBVector.h @@ -966,6 +966,12 @@ public: } void shrink_to_fit() noexcept { + if (empty()) { + // Just skip reallocation. + *this = fbvector(); + return; + } + auto const newCapacityBytes = folly::goodMallocSize(size() * sizeof(T)); auto const newCap = newCapacityBytes / sizeof(T); auto const oldCap = capacity(); -- 2.34.1