From 66aa52ae8c5867fec2fa6399cd95d8543c5948d8 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Wed, 5 Dec 2012 14:56:29 +0100 Subject: [PATCH] Fix FBVector::assign(size, v) for no-reallocation. Also add a test case. --- folly/FBVector.h | 1 + folly/test/FBVectorTest.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/folly/FBVector.h b/folly/FBVector.h index d275ec17217..318531ea1cf 100644 --- a/folly/FBVector.h +++ b/folly/FBVector.h @@ -441,6 +441,7 @@ class fbvector : private boost::totally_ordered > { // No reallocation, nice auto const newEnd = b_ + newSize; fbvector_detail::destroyRange(newEnd, e_); + std::fill(b_, newEnd, value); e_ = newEnd; return; } diff --git a/folly/test/FBVectorTest.cpp b/folly/test/FBVectorTest.cpp index 98212e188c3..e46ca811cc7 100644 --- a/folly/test/FBVectorTest.cpp +++ b/folly/test/FBVectorTest.cpp @@ -245,6 +245,21 @@ TEST(FBVector, move_iterator) { EXPECT_EQ(fbvi3, base); } +TEST(fbvector, assign_bug_no_reallocation) { + fbvector v; + v.assign(10, 20); + v.assign(10, 10); + EXPECT_EQ(v.size(), 10); + FOR_EACH (i, v) { + EXPECT_EQ(*i, 10); + } + v.assign(5, 5); + EXPECT_EQ(v.size(), 5); + FOR_EACH (i, v) { + EXPECT_EQ(*i, 5); + } +} + int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); google::ParseCommandLineFlags(&argc, &argv, true);