Update folly
Esse commit está contido em:
+4
@@ -705,12 +705,14 @@ inline size_t qfind(const Range<const char*>& haystack, const char& needle) {
|
||||
return pos == nullptr ? std::string::npos : pos - haystack.data();
|
||||
}
|
||||
|
||||
#ifdef _GNU_SOURCE // memrchr is a GNU extension
|
||||
template <>
|
||||
inline size_t rfind(const Range<const char*>& haystack, const char& needle) {
|
||||
auto pos = static_cast<const char*>(
|
||||
::memrchr(haystack.data(), needle, haystack.size()));
|
||||
return pos == nullptr ? std::string::npos : pos - haystack.data();
|
||||
}
|
||||
#endif
|
||||
|
||||
// specialization for ByteRange
|
||||
template <>
|
||||
@@ -721,6 +723,7 @@ inline size_t qfind(const Range<const unsigned char*>& haystack,
|
||||
return pos == nullptr ? std::string::npos : pos - haystack.data();
|
||||
}
|
||||
|
||||
#ifdef _GNU_SOURCE // memrchr is a GNU extension
|
||||
template <>
|
||||
inline size_t rfind(const Range<const unsigned char*>& haystack,
|
||||
const unsigned char& needle) {
|
||||
@@ -728,6 +731,7 @@ inline size_t rfind(const Range<const unsigned char*>& haystack,
|
||||
::memrchr(haystack.data(), needle, haystack.size()));
|
||||
return pos == nullptr ? std::string::npos : pos - haystack.data();
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
size_t qfind_first_of(const Range<T>& haystack,
|
||||
|
||||
+45
-6
@@ -48,9 +48,11 @@ template <class T>
|
||||
struct HasLockUnlock {
|
||||
enum { value = IsOneOf<T,
|
||||
std::mutex, std::recursive_mutex,
|
||||
std::timed_mutex, std::recursive_timed_mutex,
|
||||
boost::mutex, boost::recursive_mutex, boost::shared_mutex,
|
||||
#ifndef __APPLE__ // OSX doesn't have timed mutexes
|
||||
std::timed_mutex, std::recursive_timed_mutex,
|
||||
boost::timed_mutex, boost::recursive_timed_mutex
|
||||
#endif
|
||||
>::value };
|
||||
};
|
||||
|
||||
@@ -95,6 +97,7 @@ acquireReadWrite(T& mutex) {
|
||||
mutex.lock();
|
||||
}
|
||||
|
||||
#ifndef __APPLE__ // OSX doesn't have timed mutexes
|
||||
/**
|
||||
* Acquires a mutex for reading and writing with timeout by calling
|
||||
* .try_lock_for(). This applies to two of the std mutex classes as
|
||||
@@ -121,6 +124,7 @@ acquireReadWrite(T& mutex,
|
||||
unsigned int milliseconds) {
|
||||
return mutex.timed_lock(boost::posix_time::milliseconds(milliseconds));
|
||||
}
|
||||
#endif // __APPLE__
|
||||
|
||||
/**
|
||||
* Releases a mutex previously acquired for reading by calling
|
||||
@@ -186,8 +190,8 @@ struct Synchronized {
|
||||
* constructor.
|
||||
*/
|
||||
Synchronized() = default;
|
||||
/**
|
||||
|
||||
/**
|
||||
* Copy constructor copies the data (with locking the source and
|
||||
* all) but does NOT copy the mutex. Doing so would result in
|
||||
* deadlocks.
|
||||
@@ -216,7 +220,7 @@ struct Synchronized {
|
||||
* Constructor taking a datum rvalue as argument moves it. Again,
|
||||
* there is no need to lock the constructing object.
|
||||
*/
|
||||
explicit Synchronized(T && rhs) : datum_(std::move(rhs)) {}
|
||||
explicit Synchronized(T&& rhs) : datum_(std::move(rhs)) {}
|
||||
|
||||
/**
|
||||
* The canonical assignment operator only assigns the data, NOT the
|
||||
@@ -224,7 +228,9 @@ struct Synchronized {
|
||||
* addresses.
|
||||
*/
|
||||
Synchronized& operator=(const Synchronized& rhs) {
|
||||
if (this < *rhs) {
|
||||
if (this == &rhs) {
|
||||
// Self-assignment, pass.
|
||||
} else if (this < &rhs) {
|
||||
auto guard1 = operator->();
|
||||
auto guard2 = rhs.operator->();
|
||||
datum_ = rhs.datum_;
|
||||
@@ -236,6 +242,26 @@ struct Synchronized {
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move assignment operator, only assigns the data, NOT the
|
||||
* mutex. It locks the two objects in ascending order of their
|
||||
* addresses.
|
||||
*/
|
||||
Synchronized& operator=(Synchronized&& rhs) {
|
||||
if (this == &rhs) {
|
||||
// Self-assignment, pass.
|
||||
} else if (this < &rhs) {
|
||||
auto guard1 = operator->();
|
||||
auto guard2 = rhs.operator->();
|
||||
datum_ = std::move(rhs.datum_);
|
||||
} else {
|
||||
auto guard1 = rhs.operator->();
|
||||
auto guard2 = operator->();
|
||||
datum_ = std::move(rhs.datum_);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock object, assign datum.
|
||||
*/
|
||||
@@ -245,6 +271,15 @@ struct Synchronized {
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock object, move-assign datum.
|
||||
*/
|
||||
Synchronized& operator=(T&& rhs) {
|
||||
auto guard = operator->();
|
||||
datum_ = std::move(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A LockedPtr lp keeps a modifiable (i.e. non-const)
|
||||
* Synchronized<T> object locked for the duration of lp's
|
||||
@@ -515,7 +550,9 @@ struct Synchronized {
|
||||
}
|
||||
auto guard1 = operator->();
|
||||
auto guard2 = rhs.operator->();
|
||||
datum_.swap(rhs.datum_);
|
||||
|
||||
using std::swap;
|
||||
swap(datum_, rhs.datum_);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -524,7 +561,9 @@ struct Synchronized {
|
||||
*/
|
||||
void swap(T& rhs) {
|
||||
LockedPtr guard = operator->();
|
||||
datum_.swap(rhs);
|
||||
|
||||
using std::swap;
|
||||
swap(datum_, rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+6
@@ -385,6 +385,9 @@ dynamic parseObject(Input& in) {
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (in.getOpts().allow_trailing_comma && *in == '}') {
|
||||
break;
|
||||
}
|
||||
if (*in == '\"') { // string
|
||||
auto key = parseString(in);
|
||||
in.skipWhitespace();
|
||||
@@ -426,6 +429,9 @@ dynamic parseArray(Input& in) {
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (in.getOpts().allow_trailing_comma && *in == ']') {
|
||||
break;
|
||||
}
|
||||
ret.push_back(parseValue(in));
|
||||
in.skipWhitespace();
|
||||
if (*in != ',') {
|
||||
|
||||
+4
@@ -58,6 +58,7 @@ namespace json {
|
||||
, pretty_formatting(false)
|
||||
, encode_non_ascii(false)
|
||||
, validate_utf8(false)
|
||||
, allow_trailing_comma(false)
|
||||
{}
|
||||
|
||||
// If true, keys in an object can be non-strings. (In strict
|
||||
@@ -81,6 +82,9 @@ namespace json {
|
||||
|
||||
// Check that strings are valid utf8
|
||||
bool validate_utf8;
|
||||
|
||||
// Allow trailing comma in lists of values / items
|
||||
bool allow_trailing_comma;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário