Update folly
Esse commit está contido em:
-4
@@ -57,10 +57,6 @@
|
||||
|
||||
#include "folly/Portability.h"
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE 1
|
||||
#endif
|
||||
|
||||
#ifndef __GNUC__
|
||||
#error GCC required
|
||||
#endif
|
||||
|
||||
+80
-30
@@ -985,7 +985,7 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
// 21.3.1 construct/copy/destroy
|
||||
// C++11 21.4.2 construct/copy/destroy
|
||||
explicit basic_fbstring(const A& a = A()) {
|
||||
}
|
||||
|
||||
@@ -1047,6 +1047,11 @@ public:
|
||||
: store_(s, n, c, a) {
|
||||
}
|
||||
|
||||
// Construction from initialization list
|
||||
basic_fbstring(std::initializer_list<value_type> il) {
|
||||
assign(il.begin(), il.end());
|
||||
}
|
||||
|
||||
~basic_fbstring() {
|
||||
}
|
||||
|
||||
@@ -1076,7 +1081,7 @@ public:
|
||||
basic_fbstring& operator=(basic_fbstring&& goner) {
|
||||
if (FBSTRING_UNLIKELY(&goner == this)) {
|
||||
// Compatibility with std::basic_string<>,
|
||||
// 21.4.2 [string.cons] / 23 requires self-move-assignment support.
|
||||
// C++11 21.4.2 [string.cons] / 23 requires self-move-assignment support.
|
||||
return *this;
|
||||
}
|
||||
// No need of this anymore
|
||||
@@ -1121,11 +1126,17 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
// 21.3.2 iterators:
|
||||
basic_fbstring& operator=(std::initializer_list<value_type> il) {
|
||||
return assign(il.begin(), il.end());
|
||||
}
|
||||
|
||||
// C++11 21.4.3 iterators:
|
||||
iterator begin() { return store_.mutable_data(); }
|
||||
|
||||
const_iterator begin() const { return store_.data(); }
|
||||
|
||||
const_iterator cbegin() const { return begin(); }
|
||||
|
||||
iterator end() {
|
||||
return store_.mutable_data() + store_.size();
|
||||
}
|
||||
@@ -1134,6 +1145,8 @@ public:
|
||||
return store_.data() + store_.size();
|
||||
}
|
||||
|
||||
const_iterator cend() const { return end(); }
|
||||
|
||||
reverse_iterator rbegin() {
|
||||
return reverse_iterator(end());
|
||||
}
|
||||
@@ -1142,6 +1155,8 @@ public:
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
|
||||
const_reverse_iterator crbegin() const { return rbegin(); }
|
||||
|
||||
reverse_iterator rend() {
|
||||
return reverse_iterator(begin());
|
||||
}
|
||||
@@ -1150,6 +1165,8 @@ public:
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
|
||||
const_reverse_iterator crend() const { return rend(); }
|
||||
|
||||
// Added by C++11
|
||||
// C++11 21.4.5, element access:
|
||||
const value_type& front() const { return *begin(); }
|
||||
@@ -1169,7 +1186,7 @@ public:
|
||||
store_.shrink(1);
|
||||
}
|
||||
|
||||
// 21.3.3 capacity:
|
||||
// C++11 21.4.4 capacity:
|
||||
size_type size() const { return store_.size(); }
|
||||
|
||||
size_type length() const { return size(); }
|
||||
@@ -1213,11 +1230,19 @@ public:
|
||||
store_.reserve(res_arg);
|
||||
}
|
||||
|
||||
void shrink_to_fit() {
|
||||
// Shrink only if slack memory is sufficiently large
|
||||
if (capacity() < size() * 3 / 2) {
|
||||
return;
|
||||
}
|
||||
basic_fbstring(cbegin(), cend()).swap(*this);
|
||||
}
|
||||
|
||||
void clear() { resize(0); }
|
||||
|
||||
bool empty() const { return size() == 0; }
|
||||
|
||||
// 21.3.4 element access:
|
||||
// C++11 21.4.5 element access:
|
||||
const_reference operator[](size_type pos) const {
|
||||
return *(c_str() + pos);
|
||||
}
|
||||
@@ -1240,7 +1265,7 @@ public:
|
||||
return (*this)[n];
|
||||
}
|
||||
|
||||
// 21.3.5 modifiers:
|
||||
// C++11 21.4.6 modifiers:
|
||||
basic_fbstring& operator+=(const basic_fbstring& str) {
|
||||
return append(str);
|
||||
}
|
||||
@@ -1254,6 +1279,11 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
basic_fbstring& operator+=(std::initializer_list<value_type> il) {
|
||||
append(il);
|
||||
return *this;
|
||||
}
|
||||
|
||||
basic_fbstring& append(const basic_fbstring& str) {
|
||||
#ifndef NDEBUG
|
||||
auto desiredSize = size() + str.size();
|
||||
@@ -1323,6 +1353,10 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
basic_fbstring& append(std::initializer_list<value_type> il) {
|
||||
return append(il.begin(), il.end());
|
||||
}
|
||||
|
||||
void push_back(const value_type c) { // primitive
|
||||
store_.push_back(c);
|
||||
}
|
||||
@@ -1332,6 +1366,10 @@ public:
|
||||
return assign(str.data(), str.size());
|
||||
}
|
||||
|
||||
basic_fbstring& assign(basic_fbstring&& str) {
|
||||
return *this = std::move(str);
|
||||
}
|
||||
|
||||
basic_fbstring& assign(const basic_fbstring& str, const size_type pos,
|
||||
size_type n) {
|
||||
const size_type sz = str.size();
|
||||
@@ -1362,6 +1400,10 @@ public:
|
||||
return assign(s, traits_type::length(s));
|
||||
}
|
||||
|
||||
basic_fbstring& assign(std::initializer_list<value_type> il) {
|
||||
return assign(il.begin(), il.end());
|
||||
}
|
||||
|
||||
template <class ItOrLength, class ItOrChar>
|
||||
basic_fbstring& assign(ItOrLength first_or_n, ItOrChar last_or_c) {
|
||||
return replace(begin(), end(), first_or_n, last_or_c);
|
||||
@@ -1394,7 +1436,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
iterator insert(const iterator p, const value_type c) {
|
||||
iterator insert(const_iterator p, const value_type c) {
|
||||
const size_type pos = p - begin();
|
||||
insert(p, 1, c);
|
||||
return begin() + pos;
|
||||
@@ -1403,10 +1445,11 @@ public:
|
||||
private:
|
||||
template <int i> class Selector {};
|
||||
|
||||
basic_fbstring& insertImplDiscr(iterator p,
|
||||
size_type n, value_type c, Selector<1>) {
|
||||
iterator insertImplDiscr(const_iterator p,
|
||||
size_type n, value_type c, Selector<1>) {
|
||||
Invariant checker(*this);
|
||||
(void) checker;
|
||||
auto const pos = p - begin();
|
||||
assert(p >= begin() && p <= end());
|
||||
if (capacity() - size() < n) {
|
||||
const size_type sz = p - begin();
|
||||
@@ -1414,33 +1457,33 @@ private:
|
||||
p = begin() + sz;
|
||||
}
|
||||
const iterator oldEnd = end();
|
||||
if( n < size_type(oldEnd - p)) {
|
||||
if (n < size_type(oldEnd - p)) {
|
||||
append(oldEnd - n, oldEnd);
|
||||
//std::copy(
|
||||
// reverse_iterator(oldEnd - n),
|
||||
// reverse_iterator(p),
|
||||
// reverse_iterator(oldEnd));
|
||||
fbstring_detail::pod_move(&*p, &*oldEnd - n, &*p + n);
|
||||
std::fill(p, p + n, c);
|
||||
fbstring_detail::pod_move(&*p, &*oldEnd - n,
|
||||
begin() + pos + n);
|
||||
std::fill(begin() + pos, begin() + pos + n, c);
|
||||
} else {
|
||||
append(n - (end() - p), c);
|
||||
append(p, oldEnd);
|
||||
std::fill(p, oldEnd, c);
|
||||
append(iterator(p), oldEnd);
|
||||
std::fill(iterator(p), oldEnd, c);
|
||||
}
|
||||
store_.writeTerminator();
|
||||
return *this;
|
||||
return begin() + pos;
|
||||
}
|
||||
|
||||
template<class InputIter>
|
||||
basic_fbstring& insertImplDiscr(iterator i,
|
||||
InputIter b, InputIter e, Selector<0>) {
|
||||
insertImpl(i, b, e,
|
||||
iterator insertImplDiscr(const_iterator i,
|
||||
InputIter b, InputIter e, Selector<0>) {
|
||||
return insertImpl(i, b, e,
|
||||
typename std::iterator_traits<InputIter>::iterator_category());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class FwdIterator>
|
||||
void insertImpl(iterator i,
|
||||
iterator insertImpl(const_iterator i,
|
||||
FwdIterator s1, FwdIterator s2, std::forward_iterator_tag) {
|
||||
Invariant checker(*this);
|
||||
(void) checker;
|
||||
@@ -1462,9 +1505,9 @@ private:
|
||||
const iterator tailBegin = end() - n2;
|
||||
store_.expand_noinit(n2);
|
||||
fbstring_detail::pod_copy(tailBegin, tailBegin + n2, end() - n2);
|
||||
std::copy(reverse_iterator(tailBegin), reverse_iterator(i),
|
||||
std::copy(const_reverse_iterator(tailBegin), const_reverse_iterator(i),
|
||||
reverse_iterator(tailBegin + n2));
|
||||
std::copy(s1, s2, i);
|
||||
std::copy(s1, s2, begin() + pos);
|
||||
} else {
|
||||
FwdIterator t = s1;
|
||||
const size_type old_size = size();
|
||||
@@ -1474,27 +1517,35 @@ private:
|
||||
std::copy(t, s2, begin() + old_size);
|
||||
fbstring_detail::pod_copy(data() + pos, data() + old_size,
|
||||
begin() + old_size + newElems);
|
||||
std::copy(s1, t, i);
|
||||
std::copy(s1, t, begin() + pos);
|
||||
}
|
||||
store_.writeTerminator();
|
||||
return begin() + pos;
|
||||
}
|
||||
|
||||
template <class InputIterator>
|
||||
void insertImpl(iterator i,
|
||||
InputIterator b, InputIterator e, std::input_iterator_tag) {
|
||||
iterator insertImpl(const_iterator i,
|
||||
InputIterator b, InputIterator e,
|
||||
std::input_iterator_tag) {
|
||||
const auto pos = i - begin();
|
||||
basic_fbstring temp(begin(), i);
|
||||
for (; b != e; ++b) {
|
||||
temp.push_back(*b);
|
||||
}
|
||||
temp.append(i, end());
|
||||
temp.append(i, cend());
|
||||
swap(temp);
|
||||
return begin() + pos;
|
||||
}
|
||||
|
||||
public:
|
||||
template <class ItOrLength, class ItOrChar>
|
||||
void insert(iterator p, ItOrLength first_or_n, ItOrChar last_or_c) {
|
||||
iterator insert(const_iterator p, ItOrLength first_or_n, ItOrChar last_or_c) {
|
||||
Selector<std::numeric_limits<ItOrLength>::is_specialized> sel;
|
||||
insertImplDiscr(p, first_or_n, last_or_c, sel);
|
||||
return insertImplDiscr(p, first_or_n, last_or_c, sel);
|
||||
}
|
||||
|
||||
iterator insert(const_iterator p, std::initializer_list<value_type> il) {
|
||||
return insert(p, il.begin(), il.end());
|
||||
}
|
||||
|
||||
basic_fbstring& erase(size_type pos = 0, size_type n = npos) {
|
||||
@@ -1690,7 +1741,6 @@ public:
|
||||
store_.swap(rhs.store_);
|
||||
}
|
||||
|
||||
// 21.3.6 string operations:
|
||||
const value_type* c_str() const {
|
||||
return store_.c_str();
|
||||
}
|
||||
@@ -2165,7 +2215,7 @@ bool operator>=(const typename basic_fbstring<E, T, A, S>::value_type* lhs,
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
// subclause 21.3.7.8:
|
||||
// C++11 21.4.8.8
|
||||
template <typename E, class T, class A, class S>
|
||||
void swap(basic_fbstring<E, T, A, S>& lhs, basic_fbstring<E, T, A, S>& rhs) {
|
||||
lhs.swap(rhs);
|
||||
|
||||
+33
@@ -21,6 +21,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <tuple>
|
||||
|
||||
#include "folly/SpookyHashV1.h"
|
||||
#include "folly/SpookyHashV2.h"
|
||||
@@ -348,6 +349,26 @@ template<> struct hasher<uint64_t> {
|
||||
}
|
||||
};
|
||||
|
||||
// recursion
|
||||
template <size_t index, typename... Ts>
|
||||
struct TupleHasher {
|
||||
size_t operator()(std::tuple<Ts...> const& key) const {
|
||||
return hash::hash_combine(
|
||||
TupleHasher<index - 1, Ts...>()(key),
|
||||
std::get<index>(key));
|
||||
}
|
||||
};
|
||||
|
||||
// base
|
||||
template <typename... Ts>
|
||||
struct TupleHasher<0, Ts...> {
|
||||
size_t operator()(std::tuple<Ts...> const& key) const {
|
||||
// we could do std::hash here directly, but hash_combine hides all the
|
||||
// ugly templating implicitly
|
||||
return hash::hash_combine(std::get<0>(key));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace folly
|
||||
|
||||
// Custom hash functions.
|
||||
@@ -361,6 +382,18 @@ namespace std {
|
||||
return folly::hash::hash_combine(x.first, x.second);
|
||||
}
|
||||
};
|
||||
|
||||
// Hash function for tuples. Requires default hash functions for all types.
|
||||
template <typename... Ts>
|
||||
struct hash<std::tuple<Ts...>> {
|
||||
size_t operator()(std::tuple<Ts...> const& key) const {
|
||||
folly::TupleHasher<
|
||||
std::tuple_size<std::tuple<Ts...>>::value - 1, // start index
|
||||
Ts...> hasher;
|
||||
|
||||
return hasher(key);
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
#endif
|
||||
|
||||
+15
@@ -443,6 +443,13 @@ void join(const Delim& delimiter,
|
||||
join(delimiter, container.begin(), container.end(), output);
|
||||
}
|
||||
|
||||
template <class Delim, class Value, class String>
|
||||
void join(const Delim& delimiter,
|
||||
const std::initializer_list<Value>& values,
|
||||
String& output) {
|
||||
join(delimiter, values.begin(), values.end(), output);
|
||||
}
|
||||
|
||||
template <class Delim, class Container>
|
||||
std::string join(const Delim& delimiter,
|
||||
const Container& container) {
|
||||
@@ -451,6 +458,14 @@ std::string join(const Delim& delimiter,
|
||||
return output;
|
||||
}
|
||||
|
||||
template <class Delim, class Value>
|
||||
std::string join(const Delim& delimiter,
|
||||
const std::initializer_list<Value>& values) {
|
||||
std::string output;
|
||||
join(delimiter, values.begin(), values.end(), output);
|
||||
return output;
|
||||
}
|
||||
|
||||
} // namespace folly
|
||||
|
||||
// Hash functions for string and fbstring usable with e.g. hash_map
|
||||
|
||||
+77
-5
@@ -1675,11 +1675,11 @@ class RangeConcat : public Operator<RangeConcat> {
|
||||
public:
|
||||
RangeConcat() { }
|
||||
|
||||
template<class Source,
|
||||
class Range,
|
||||
template<class Range,
|
||||
class Source,
|
||||
class InnerValue = typename ValueTypeOfRange<Range>::RefType>
|
||||
class Generator
|
||||
: public GenImpl<InnerValue, Generator<Source, Range, InnerValue>> {
|
||||
: public GenImpl<InnerValue, Generator<Range, Source, InnerValue>> {
|
||||
Source source_;
|
||||
public:
|
||||
explicit Generator(Source source)
|
||||
@@ -1709,19 +1709,91 @@ class RangeConcat : public Operator<RangeConcat> {
|
||||
|
||||
template<class Value,
|
||||
class Source,
|
||||
class Gen = Generator<Source, Value>>
|
||||
class Gen = Generator<Value, Source>>
|
||||
Gen compose(GenImpl<Value, Source>&& source) const {
|
||||
return Gen(std::move(source.self()));
|
||||
}
|
||||
|
||||
template<class Value,
|
||||
class Source,
|
||||
class Gen = Generator<Source, Value>>
|
||||
class Gen = Generator<Value, Source>>
|
||||
Gen compose(const GenImpl<Value, Source>& source) const {
|
||||
return Gen(source.self());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* GuardImpl - For handling exceptions from downstream computation. Requires the
|
||||
* type of exception to catch, and handler function to invoke in the event of
|
||||
* the exception. Note that the handler may:
|
||||
* 1) return true to continue processing the sequence
|
||||
* 2) return false to end the sequence immediately
|
||||
* 3) throw, to pass the exception to the next catch
|
||||
* The handler must match the signature 'bool(Exception&, Value)'.
|
||||
*
|
||||
* This type is used through the `guard` helper, like so:
|
||||
*
|
||||
* auto indexes
|
||||
* = byLine(STDIN_FILENO)
|
||||
* | guard<std::runtime_error>([](std::runtime_error& e,
|
||||
* StringPiece sp) {
|
||||
* LOG(ERROR) << sp << ": " << e.str();
|
||||
* return true; // continue processing subsequent lines
|
||||
* })
|
||||
* | eachTo<int>()
|
||||
* | as<vector>();
|
||||
*
|
||||
* TODO(tjackson): Rename this back to Guard.
|
||||
**/
|
||||
template<class Exception,
|
||||
class ErrorHandler>
|
||||
class GuardImpl : public Operator<GuardImpl<Exception, ErrorHandler>> {
|
||||
ErrorHandler handler_;
|
||||
public:
|
||||
GuardImpl(ErrorHandler handler)
|
||||
: handler_(std::move(handler)) {}
|
||||
|
||||
template<class Value,
|
||||
class Source>
|
||||
class Generator : public GenImpl<Value, Generator<Value, Source>> {
|
||||
Source source_;
|
||||
ErrorHandler handler_;
|
||||
public:
|
||||
explicit Generator(Source source,
|
||||
ErrorHandler handler)
|
||||
: source_(std::move(source)),
|
||||
handler_(std::move(handler)) {}
|
||||
|
||||
template<class Handler>
|
||||
bool apply(Handler&& handler) const {
|
||||
return source_.apply([&](Value value) -> bool {
|
||||
try {
|
||||
handler(std::forward<Value>(value));
|
||||
return true;
|
||||
} catch (Exception& e) {
|
||||
return handler_(e, std::forward<Value>(value));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static constexpr bool infinite = Source::infinite;
|
||||
};
|
||||
|
||||
template<class Value,
|
||||
class Source,
|
||||
class Gen = Generator<Value, Source>>
|
||||
Gen compose(GenImpl<Value, Source>&& source) const {
|
||||
return Gen(std::move(source.self()), handler_);
|
||||
}
|
||||
|
||||
template<class Value,
|
||||
class Source,
|
||||
class Gen = Generator<Value, Source>>
|
||||
Gen compose(const GenImpl<Value, Source>& source) const {
|
||||
return Gen(source.self(), handler_);
|
||||
}
|
||||
};
|
||||
} //::detail
|
||||
|
||||
/**
|
||||
|
||||
@@ -343,6 +343,10 @@ struct GeneratorBuilder;
|
||||
template<class Needle>
|
||||
class Contains;
|
||||
|
||||
template<class Exception,
|
||||
class ErrorHandler>
|
||||
class GuardImpl;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -622,6 +626,16 @@ Contains contains(Needle&& needle) {
|
||||
return Contains(std::forward<Needle>(needle));
|
||||
}
|
||||
|
||||
template<class Exception,
|
||||
class ErrorHandler,
|
||||
class GuardImpl =
|
||||
detail::GuardImpl<
|
||||
Exception,
|
||||
typename std::decay<ErrorHandler>::type>>
|
||||
GuardImpl guard(ErrorHandler&& handler) {
|
||||
return GuardImpl(std::forward<ErrorHandler>(handler));
|
||||
}
|
||||
|
||||
}} // folly::gen
|
||||
|
||||
#include "folly/experimental/Gen-inl.h"
|
||||
|
||||
@@ -201,7 +201,6 @@ RecordInfo findRecord(ByteRange searchRange,
|
||||
static const uint32_t magic = Header::kMagic;
|
||||
static const ByteRange magicRange(reinterpret_cast<const uint8_t*>(&magic),
|
||||
sizeof(magic));
|
||||
static constexpr size_t headerTail = sizeof(Header) - sizeof(magic);
|
||||
|
||||
DCHECK_GE(searchRange.begin(), wholeRange.begin());
|
||||
DCHECK_LE(searchRange.end(), wholeRange.end());
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário