fix(FBString): fix bugs v2016.08.22.00
authorpp__qq <p_qp__q@163.com>
Mon, 22 Aug 2016 04:50:45 +0000 (21:50 -0700)
committerFacebook Github Bot 8 <facebook-github-bot-8-bot@fb.com>
Mon, 22 Aug 2016 04:53:25 +0000 (21:53 -0700)
Summary:
fix(FBString): compile error on instantiate `basic_fbstring` with a `Storage` that is not `fbstring_core<E>`
Closes https://github.com/facebook/folly/pull/398

Reviewed By: ot

Differential Revision: D3714957

Pulled By: yfeldblum

fbshipit-source-id: 1c5d2538b674049f7e1872a0b623ec330dc8d7b2

folly/FBString.h

index 8d6f19c2b6c6761b358439182de3988cf4d19e8b..8c4e5889a782e532b441b142143d7a45a6e431a1 100644 (file)
@@ -1106,7 +1106,7 @@ public:
     // No need of this anymore
     this->~basic_fbstring();
     // Move the goner into this
-    new(&store_) fbstring_core<E>(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);
     }