From 572543f40b0ee7eea53e707e0120d25b73248206 Mon Sep 17 00:00:00 2001 From: pp__qq Date: Sun, 21 Aug 2016 21:50:45 -0700 Subject: [PATCH] fix(FBString): fix bugs Summary: fix(FBString): compile error on instantiate `basic_fbstring` with a `Storage` that is not `fbstring_core` Closes https://github.com/facebook/folly/pull/398 Reviewed By: ot Differential Revision: D3714957 Pulled By: yfeldblum fbshipit-source-id: 1c5d2538b674049f7e1872a0b623ec330dc8d7b2 --- folly/FBString.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/folly/FBString.h b/folly/FBString.h index 8d6f19c2..8c4e5889 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -1106,7 +1106,7 @@ public: // No need of this anymore this->~basic_fbstring(); // Move the goner into this - new(&store_) fbstring_core(std::move(goner.store_)); + new (&store_) Storage(std::move(goner.store_)); return *this; } @@ -1387,7 +1387,9 @@ public: assert(size() == n); } else { const value_type *const s2 = s + size(); - fbstring_detail::pod_move(s, s2, store_.mutable_data()); + // size() < n!so [s,s + n) and [data(),data() + size()] can not overlap + // so we can use pod_copy instead of pod_move. + fbstring_detail::pod_copy(s, s2, store_.mutable_data()); append(s2, n - size()); assert(size() == n); } @@ -1436,7 +1438,7 @@ public: } iterator insert(const_iterator p, const value_type c) { - const size_type pos = p - begin(); + const size_type pos = p - cbegin(); insert(p, 1, c); return begin() + pos; } @@ -1491,8 +1493,8 @@ private: size_type n, value_type c, Selector<1>) { Invariant checker(*this); - assert(i >= begin() && i <= end()); - const size_type pos = i - begin(); + assert(i >= cbegin() && i <= cend()); + const size_type pos = i - cbegin(); auto oldSize = size(); store_.expand_noinit(n, /* expGrowth = */ true); @@ -1517,8 +1519,8 @@ private: std::forward_iterator_tag) { Invariant checker(*this); - assert(i >= begin() && i <= end()); - const size_type pos = i - begin(); + assert(i >= cbegin() && i <= cend()); + const size_type pos = i - cbegin(); auto n = std::distance(s1, s2); assert(n >= 0); @@ -1535,8 +1537,8 @@ private: iterator insertImpl(const_iterator i, InputIterator b, InputIterator e, std::input_iterator_tag) { - const auto pos = i - begin(); - basic_fbstring temp(begin(), i); + const auto pos = i - cbegin(); + basic_fbstring temp(cbegin(), i); for (; b != e; ++b) { temp.push_back(*b); } -- 2.34.1