Commit 572543f4 authored by pp__qq's avatar pp__qq Committed by Facebook Github Bot 8

fix(FBString): fix bugs

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
parent 7ae5a5e4
......@@ -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);
}
......
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