projects
/
folly.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
140c62d
)
Skip reallocation in shrink_to_fit for empty fbvector
author
Giuseppe Ottaviano
<ott@fb.com>
Wed, 25 Nov 2015 21:39:14 +0000
(13:39 -0800)
committer
facebook-github-bot-1
<folly-bot@fb.com>
Wed, 25 Nov 2015 22:20:21 +0000
(14:20 -0800)
Reviewed By: philippv
Differential Revision:
D2696314
fb-gh-sync-id:
105de2d99bb9f5ac82310e37f9302022c103befc
folly/FBVector.h
patch
|
blob
|
history
diff --git
a/folly/FBVector.h
b/folly/FBVector.h
index 22d76034bf084d5ce249fe50665e286c13f7777a..c773a7f963dc023b01942eba114345d1449002cf 100644
(file)
--- 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();