Commit c78e8cf4 authored by Christian Kamm's avatar Christian Kamm Committed by Jordan DeLong

Fix bug in reserve() and shrink_to_fit().

Summary:
impl_.e_ += newB - impl_.b_; fails when the difference
between newB and impl_.b_ isn't a multiple of sizeof(T).

Test Plan: .

Reviewed By: oyamauchi@fb.com

FB internal diff: D774754
parent e33bebd3
......@@ -1095,7 +1095,7 @@ public:
if (impl_.b_)
M_deallocate(impl_.b_, impl_.z_ - impl_.b_);
impl_.z_ = newB + newCap;
impl_.e_ += newB - impl_.b_; // speed hax
impl_.e_ = newB + (impl_.e_ - impl_.b_);
impl_.b_ = newB;
}
......@@ -1128,7 +1128,7 @@ public:
if (impl_.b_)
M_deallocate(impl_.b_, impl_.z_ - impl_.b_);
impl_.z_ = newB + newCap;
impl_.e_ += newB - impl_.b_; // speed hax
impl_.e_ = newB + (impl_.e_ - impl_.b_);
impl_.b_ = newB;
}
}
......
......@@ -245,6 +245,17 @@ TEST(FBVector, move_iterator) {
EXPECT_EQ(fbvi3, base);
}
TEST(FBVector, reserve_consistency) {
struct S { int64_t a, b, c, d; };
fbvector<S> fb1;
for (size_t i = 0; i < 1000; ++i) {
fb1.reserve(1);
EXPECT_EQ(fb1.size(), 0);
fb1.shrink_to_fit();
}
}
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
google::ParseCommandLineFlags(&argc, &argv, true);
......
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