Allocator, ProbeFcn, KeyConvertFcn>::
encodeIndex(uint32_t subMap, uint32_t offset) {
DCHECK_EQ(offset & kSecondaryMapBit_, 0); // offset can't be too big
- if (subMap == 0) return offset;
+ if (subMap == 0) {
+ return offset;
+ }
// Make sure subMap isn't too big
DCHECK_EQ(subMap >> kNumSubMapBits_, 0);
// Make sure subMap bits of offset are clear
height_(height), data_(std::forward<U>(data)) {
spinLock_.init();
setFlags(0);
- if (isHead) setIsHeadNode();
+ if (isHead) {
+ setIsHeadNode();
+ }
// need to explicitly init the dynamic atomic pointer array
for (uint8_t i = 0; i < height_; ++i) {
new (&skip_[i]) std::atomic<SkipListNode*>(nullptr);
// Returns the node if found, nullptr otherwise.
NodeType* find(const value_type &data) {
auto ret = findNode(data);
- if (ret.second && !ret.first->markedForRemoval()) return ret.first;
+ if (ret.second && !ret.first->markedForRemoval()) {
+ return ret.first;
+ }
return nullptr;
}
nodeToDelete = succs[layer];
nodeHeight = nodeToDelete->height();
nodeGuard = nodeToDelete->acquireGuard();
- if (nodeToDelete->markedForRemoval()) return false;
+ if (nodeToDelete->markedForRemoval()) {
+ return false;
+ }
nodeToDelete->setMarkedForRemoval();
isMarked = true;
}
for (int layer = maxLayer(); layer >= 0; --layer) {
do {
node = pred->skip(layer);
- if (node) pred = node;
+ if (node) {
+ pred = node;
+ }
} while (node != nullptr);
}
return pred == head_.load(std::memory_order_relaxed)
while (!found) {
// stepping down
for (; ht > 0 && less(data, node = pred->skip(ht - 1)); --ht) {}
- if (ht == 0) return std::make_pair(node, 0); // not found
+ if (ht == 0) {
+ return std::make_pair(node, 0); // not found
+ }
// node <= data now, but we need to fix up ht
--ht;
*/
bool to(const value_type &data) {
int layer = curHeight() - 1;
- if (layer < 0) return false; // reaches the end of the list
+ if (layer < 0) {
+ return false; // reaches the end of the list
+ }
int lyr = hints_[layer];
int max_layer = maxLayer();
int foundLayer = SkipListType::
findInsertionPoint(preds_[lyr], lyr, data, preds_, succs_);
- if (foundLayer < 0) return false;
+ if (foundLayer < 0) {
+ return false;
+ }
DCHECK(succs_[0] != nullptr) << "lyr=" << lyr
<< "; max_layer=" << max_layer;
struct CheckTrailingSpace {
Expected<Unit, ConversionCode> operator()(StringPiece sp) const {
auto e = enforceWhitespaceErr(sp);
- if (UNLIKELY(e != ConversionCode::SUCCESS))
+ if (UNLIKELY(e != ConversionCode::SUCCESS)) {
return makeUnexpected(e);
+ }
return unit;
}
};
template <typename V>
typename dptr_detail::VisitorResult<V, Types...>::type apply(V&& visitor) {
size_t n = index();
- if (n == 0) throw std::invalid_argument("Empty DiscriminatedPtr");
+ if (n == 0) {
+ throw std::invalid_argument("Empty DiscriminatedPtr");
+ }
return dptr_detail::ApplyVisitor<V, Types...>()(
n, std::forward<V>(visitor), ptr());
}
typename dptr_detail::ConstVisitorResult<V, Types...>::type apply(V&& visitor)
const {
size_t n = index();
- if (n == 0) throw std::invalid_argument("Empty DiscriminatedPtr");
+ if (n == 0) {
+ throw std::invalid_argument("Empty DiscriminatedPtr");
+ }
return dptr_detail::ApplyConstVisitor<V, Types...>()(
n, std::forward<V>(visitor), ptr());
}
}
template <class Other>
void assign(Other&& that) {
- if (isSelfAssign(&that))
+ if (isSelfAssign(&that)) {
return;
+ }
switch (that.which_) {
case Which::eValue:
this->assignValue(static_cast<Other&&>(that).value());
T::template return_<E>(
(std::declval<Fn>()(std::declval<This>().value()), unit)),
std::declval<Fns>()...)) {
- if (LIKELY(ex.which_ == expected_detail::Which::eValue))
+ if (LIKELY(ex.which_ == expected_detail::Which::eValue)) {
return T::then_(
T::template return_<E>(
// Uses the comma operator defined above IFF the lambda
// returns non-void.
(static_cast<Fn&&>(fn)(static_cast<This&&>(ex).value()), unit)),
static_cast<Fns&&>(fns)...);
+ }
return makeUnexpected(static_cast<This&&>(ex).error());
}
class Err = decltype(std::declval<No>()(std::declval<This>().error()))
FOLLY_REQUIRES_TRAILING(!std::is_void<Err>::value)>
static Ret thenOrThrow_(This&& ex, Yes&& yes, No&& no) {
- if (LIKELY(ex.which_ == expected_detail::Which::eValue))
+ if (LIKELY(ex.which_ == expected_detail::Which::eValue)) {
return Ret(static_cast<Yes&&>(yes)(static_cast<This&&>(ex).value()));
+ }
throw static_cast<No&&>(no)(static_cast<This&&>(ex).error());
}
class Err = decltype(std::declval<No>()(std::declval<This&>().error()))
FOLLY_REQUIRES_TRAILING(std::is_void<Err>::value)>
static Ret thenOrThrow_(This&& ex, Yes&& yes, No&& no) {
- if (LIKELY(ex.which_ == expected_detail::Which::eValue))
+ if (LIKELY(ex.which_ == expected_detail::Which::eValue)) {
return Ret(static_cast<Yes&&>(yes)(static_cast<This&&>(ex).value()));
+ }
static_cast<No&&>(no)(ex.error());
throw typename Unexpected<ExpectedErrorType<This>>::MakeBadExpectedAccess()(
static_cast<This&&>(ex).error());
*/
void swap(Expected& that) noexcept(
expected_detail::StrictAllOf<IsNothrowSwappable, Value, Error>::value) {
- if (this->uninitializedByException() || that.uninitializedByException())
+ if (this->uninitializedByException() || that.uninitializedByException()) {
throw BadExpectedAccess();
+ }
using std::swap;
if (*this) {
if (that) {
expected_detail::ExpectedHelper::then_(
std::declval<const Base&>(),
std::declval<Fns>()...)) {
- if (this->uninitializedByException())
+ if (this->uninitializedByException()) {
throw BadExpectedAccess();
+ }
return expected_detail::ExpectedHelper::then_(
base(), static_cast<Fns&&>(fns)...);
}
auto then(Fns&&... fns) & -> decltype(expected_detail::ExpectedHelper::then_(
std::declval<Base&>(),
std::declval<Fns>()...)) {
- if (this->uninitializedByException())
+ if (this->uninitializedByException()) {
throw BadExpectedAccess();
+ }
return expected_detail::ExpectedHelper::then_(
base(), static_cast<Fns&&>(fns)...);
}
auto then(Fns&&... fns) && -> decltype(expected_detail::ExpectedHelper::then_(
std::declval<Base&&>(),
std::declval<Fns>()...)) {
- if (this->uninitializedByException())
+ if (this->uninitializedByException()) {
throw BadExpectedAccess();
+ }
return expected_detail::ExpectedHelper::then_(
std::move(base()), static_cast<Fns&&>(fns)...);
}
auto thenOrThrow(Yes&& yes, No&& no = No{}) const& -> decltype(
std::declval<Yes>()(std::declval<const Value&>())) {
using Ret = decltype(std::declval<Yes>()(std::declval<const Value&>()));
- if (this->uninitializedByException())
+ if (this->uninitializedByException()) {
throw BadExpectedAccess();
+ }
return Ret(expected_detail::ExpectedHelper::thenOrThrow_(
base(), static_cast<Yes&&>(yes), static_cast<No&&>(no)));
}
auto thenOrThrow(Yes&& yes, No&& no = No{}) & -> decltype(
std::declval<Yes>()(std::declval<Value&>())) {
using Ret = decltype(std::declval<Yes>()(std::declval<Value&>()));
- if (this->uninitializedByException())
+ if (this->uninitializedByException()) {
throw BadExpectedAccess();
+ }
return Ret(expected_detail::ExpectedHelper::thenOrThrow_(
base(), static_cast<Yes&&>(yes), static_cast<No&&>(no)));
}
auto thenOrThrow(Yes&& yes, No&& no = No{}) && -> decltype(
std::declval<Yes>()(std::declval<Value&&>())) {
using Ret = decltype(std::declval<Yes>()(std::declval<Value&&>()));
- if (this->uninitializedByException())
+ if (this->uninitializedByException()) {
throw BadExpectedAccess();
+ }
return Ret(expected_detail::ExpectedHelper::thenOrThrow_(
std::move(base()), static_cast<Yes&&>(yes), static_cast<No&&>(no)));
}
private:
void requireValue() const {
if (UNLIKELY(!hasValue())) {
- if (LIKELY(hasError()))
+ if (LIKELY(hasError())) {
throw typename Unexpected<Error>::BadExpectedAccess(this->error_);
+ }
throw BadExpectedAccess();
}
}
operator==(
const Expected<Value, Error>& lhs,
const Expected<Value, Error>& rhs) {
- if (UNLIKELY(lhs.which_ != rhs.which_))
+ if (UNLIKELY(lhs.which_ != rhs.which_)) {
return UNLIKELY(lhs.uninitializedByException()) ? false
: throw BadExpectedAccess();
- if (UNLIKELY(lhs.uninitializedByException()))
+ }
+ if (UNLIKELY(lhs.uninitializedByException())) {
throw BadExpectedAccess();
- if (UNLIKELY(lhs.hasError()))
+ }
+ if (UNLIKELY(lhs.hasError())) {
return true; // All error states are considered equal
+ }
return lhs.value_ == rhs.value_;
}
const Expected<Value, Error>& lhs,
const Expected<Value, Error>& rhs) {
if (UNLIKELY(
- lhs.uninitializedByException() || rhs.uninitializedByException()))
+ lhs.uninitializedByException() || rhs.uninitializedByException())) {
throw BadExpectedAccess();
- if (UNLIKELY(lhs.hasError()))
+ }
+ if (UNLIKELY(lhs.hasError())) {
return !rhs.hasError();
- if (UNLIKELY(rhs.hasError()))
+ }
+ if (UNLIKELY(rhs.hasError())) {
return false;
+ }
return lhs.value_ < rhs.value_;
}
}
basic_fbstring& assign(const basic_fbstring& str) {
- if (&str == this) return *this;
+ if (&str == this) {
+ return *this;
+ }
return assign(str.data(), str.size());
}
static void swap(Impl& a, Impl& b) {
using std::swap;
- if (!usingStdAllocator::value) swap<Allocator>(a, b);
+ if (!usingStdAllocator::value) {
+ swap<Allocator>(a, b);
+ }
a.swapData(b);
}
void M_destroy(T* p) noexcept {
if (usingStdAllocator::value) {
- if (!std::is_trivially_destructible<T>::value)
+ if (!std::is_trivially_destructible<T>::value) {
p->~T();
+ }
} else {
std::allocator_traits<Allocator>::destroy(impl_, p);
}
// allocator
static void S_destroy_range_a(Allocator& a, T* first, T* last) noexcept {
- for (; first != last; ++first)
+ for (; first != last; ++first) {
std::allocator_traits<Allocator>::destroy(a, first);
+ }
}
// optimized
auto b = dest;
auto e = dest + sz;
try {
- for (; b != e; ++b)
+ for (; b != e; ++b) {
std::allocator_traits<Allocator>::construct(a, b,
std::forward<Args>(args)...);
+ }
} catch (...) {
S_destroy_range_a(a, dest, b);
throw;
auto b = dest;
auto e = dest + n;
try {
- for (; b != e; ++b) S_construct(b);
+ for (; b != e; ++b) {
+ S_construct(b);
+ }
} catch (...) {
--b;
- for (; b >= dest; --b) b->~T();
+ for (; b >= dest; --b) {
+ b->~T();
+ }
throw;
}
}
auto b = dest;
auto e = dest + n;
try {
- for (; b != e; ++b) S_construct(b, value);
+ for (; b != e; ++b) {
+ S_construct(b, value);
+ }
} catch (...) {
S_destroy_range(dest, b);
throw;
S_uninitialized_copy_a(Allocator& a, T* dest, It first, It last) {
auto b = dest;
try {
- for (; first != last; ++first, ++b)
+ for (; first != last; ++first, ++b) {
std::allocator_traits<Allocator>::construct(a, b, *first);
+ }
} catch (...) {
S_destroy_range_a(a, dest, b);
throw;
static void S_uninitialized_copy(T* dest, It first, It last) {
auto b = dest;
try {
- for (; first != last; ++first, ++b)
+ for (; first != last; ++first, ++b) {
S_construct(b, *first);
+ }
} catch (...) {
S_destroy_range(dest, b);
throw;
template <typename It>
static It S_copy_n(T* dest, It first, size_type n) {
auto e = dest + n;
- for (; dest != e; ++dest, ++first) *dest = *first;
+ for (; dest != e; ++dest, ++first) {
+ *dest = *first;
+ }
return first;
}
~fbvector() = default; // the cleanup occurs in impl_
fbvector& operator=(const fbvector& other) {
- if (UNLIKELY(this == &other)) return *this;
+ if (UNLIKELY(this == &other)) {
+ return *this;
+ }
if (!usingStdAllocator::value &&
A::propagate_on_container_copy_assignment::value) {
}
fbvector& operator=(fbvector&& other) {
- if (UNLIKELY(this == &other)) return *this;
+ if (UNLIKELY(this == &other)) {
+ return *this;
+ }
moveFrom(std::move(other), moveIsSwap());
return *this;
}
{ M_uninitialized_copy_e(first, last); }
template <class InputIterator>
- fbvector(InputIterator first, InputIterator last,
- const Allocator& a, std::input_iterator_tag)
- : impl_(a)
- { for (; first != last; ++first) emplace_back(*first); }
+ fbvector(
+ InputIterator first,
+ InputIterator last,
+ const Allocator& a,
+ std::input_iterator_tag)
+ : impl_(a) {
+ for (; first != last; ++first) {
+ emplace_back(*first);
+ }
+ }
// contract dispatch for allocator movement in operator=(fbvector&&)
void
if (p != impl_.e_) {
M_destroy_range_e(p);
} else {
- for (; first != last; ++first) emplace_back(*first);
+ for (; first != last; ++first) {
+ emplace_back(*first);
+ }
}
}
// contract dispatch for aliasing under VT optimization
bool dataIsInternalAndNotVT(const T& t) {
- if (should_pass_by_value::value) return false;
+ if (should_pass_by_value::value) {
+ return false;
+ }
return dataIsInternal(t);
}
bool dataIsInternal(const T& t) {
}
void reserve(size_type n) {
- if (n <= capacity()) return;
- if (impl_.b_ && reserve_in_place(n)) return;
+ if (n <= capacity()) {
+ return;
+ }
+ if (impl_.b_ && reserve_in_place(n)) {
+ return;
+ }
auto newCap = folly::goodMallocSize(n * sizeof(T)) / sizeof(T);
auto newB = M_allocate(newCap);
M_deallocate(newB, newCap);
throw;
}
- if (impl_.b_)
+ if (impl_.b_) {
M_deallocate(impl_.b_, size_type(impl_.z_ - impl_.b_));
+ }
impl_.z_ = newB + newCap;
impl_.e_ = newB + (impl_.e_ - impl_.b_);
impl_.b_ = newB;
auto const newCap = newCapacityBytes / sizeof(T);
auto const oldCap = capacity();
- if (newCap >= oldCap) return;
+ if (newCap >= oldCap) {
+ return;
+ }
void* p = impl_.b_;
// xallocx() will shrink to precisely newCapacityBytes (which was generated
} catch (...) {
return;
}
- if (impl_.b_)
+ if (impl_.b_) {
M_deallocate(impl_.b_, size_type(impl_.z_ - impl_.b_));
+ }
impl_.z_ = newB + newCap;
impl_.e_ = newB + (impl_.e_ - impl_.b_);
impl_.b_ = newB;
private:
bool reserve_in_place(size_type n) {
- if (!usingStdAllocator::value || !usingJEMalloc()) return false;
+ if (!usingStdAllocator::value || !usingJEMalloc()) {
+ return false;
+ }
// jemalloc can never grow in place blocks smaller than 4096 bytes.
if ((impl_.z_ - impl_.b_) * sizeof(T) <
- folly::jemallocMinInPlaceExpandable) return false;
+ folly::jemallocMinInPlaceExpandable) {
+ return false;
+ }
auto const newCapacityBytes = folly::goodMallocSize(n * sizeof(T));
void* p = impl_.b_;
}
void swap(fbvector& other) noexcept {
- if (!usingStdAllocator::value &&
- A::propagate_on_container_swap::value)
+ if (!usingStdAllocator::value && A::propagate_on_container_swap::value) {
swap(impl_, other.impl_);
- else impl_.swapData(other.impl_);
+ } else {
+ impl_.swapData(other.impl_);
+ }
}
void clear() noexcept {
bool insert_use_fresh(bool at_end, size_type n) {
if (at_end) {
- if (size() + n <= capacity()) return false;
- if (reserve_in_place(size() + n)) return false;
+ if (size() + n <= capacity()) {
+ return false;
+ }
+ if (reserve_in_place(size() + n)) {
+ return false;
+ }
return true;
}
- if (size() + n > capacity()) return true;
+ if (size() + n > capacity()) {
+ return true;
+ }
return false;
}
std::make_move_iterator(end()),
A::select_on_container_copy_construction(impl_));
M_destroy_range_e(position);
- for (; first != last; ++first) emplace_back(*first);
+ for (; first != last; ++first) {
+ emplace_back(*first);
+ }
insert(cend(), std::make_move_iterator(storage.begin()),
std::make_move_iterator(storage.end()));
return impl_.b_ + idx;
M_deallocate(newB, sz);
throw;
}
- if (impl_.b_) M_deallocate(impl_.b_, size());
+ if (impl_.b_) {
+ M_deallocate(impl_.b_, size());
+ }
impl_.b_ = newB;
impl_.e_ = newE;
impl_.z_ = newB + sz;
bool File::doTryLock(int op) {
int r = flockNoInt(fd_, op | LOCK_NB);
// flock returns EWOULDBLOCK if already locked
- if (r == -1 && errno == EWOULDBLOCK) return false;
+ if (r == -1 && errno == EWOULDBLOCK) {
+ return false;
+ }
checkUnixError(r, "flock() failed (try_lock)");
return true;
}
// Obtain file size:
struct stat buf;
- if (fstat(fd, &buf) == -1) return false;
+ if (fstat(fd, &buf) == -1) {
+ return false;
+ }
// Some files (notably under /proc and /sys on Linux) lie about
// their size, so treat the size advertised by fstat under advise
// but don't rely on it. In particular, if the size is zero, we
Fingerprint() {
// Use a non-zero starting value. We'll use (1 << (BITS-1))
fp_[0] = 1ULL << 63;
- for (int i = 1; i < size(); i++)
+ for (int i = 1; i < size(); i++) {
fp_[i] = 0;
+ }
}
Fingerprint& update8(uint8_t v) {
std::size_t count,
Char ch) noexcept(false) {
detail::fixedstring::checkOverflow(count, N - size_);
- for (std::size_t i = 0u; i < count; ++i)
+ for (std::size_t i = 0u; i < count; ++i) {
data_[size_ + i] = ch;
+ }
size_ += count;
data_[size_] = Char(0);
return *this;
detail::fixedstring::checkOverflow(pos, that.size_);
count = detail::fixedstring::checkOverflowOrNpos(count, that.size_ - pos);
detail::fixedstring::checkOverflow(count, N - size_);
- for (std::size_t i = 0u; i < count; ++i)
+ for (std::size_t i = 0u; i < count; ++i) {
data_[size_ + i] = that.data_[pos + i];
+ }
size_ += count;
data_[size_] = Char(0);
return *this;
const Char* that,
std::size_t count) noexcept(false) {
detail::fixedstring::checkOverflow(count, N - size_);
- for (std::size_t i = 0u; i < count; ++i)
+ for (std::size_t i = 0u; i < count; ++i) {
data_[size_ + i] = that[i];
+ }
size_ += count;
data_[size_] = Char(0);
return *this;
copy(Char* dest, std::size_t count, std::size_t pos) const noexcept(false) {
detail::fixedstring::checkOverflow(pos, size_);
for (std::size_t i = 0u; i < count; ++i) {
- if (i + pos == size_)
+ if (i + pos == size_) {
return size_;
+ }
dest[i] = data_[i + pos];
}
return count;
template <class T, class U>
typename std::enable_if<!HasLess<U, T>::value, bool>::type
downTo(T& iter, const U& begin) {
- if (iter == begin) return false;
+ if (iter == begin) {
+ return false;
+ }
--iter;
return true;
}
if (*p == ':') {
// parse format spec
- if (++p == end) return;
+ if (++p == end) {
+ return;
+ }
// fill/align, or just align
Align a;
fill = *p;
align = a;
p += 2;
- if (p == end) return;
+ if (p == end) {
+ return;
+ }
} else if ((a = formatAlignTable[static_cast<unsigned char>(*p)]) !=
Align::INVALID) {
align = a;
- if (++p == end) return;
+ if (++p == end) {
+ return;
+ }
}
Sign s;
unsigned char uSign = static_cast<unsigned char>(*p);
if ((s = formatSignTable[uSign]) != Sign::INVALID) {
sign = s;
- if (++p == end) return;
+ if (++p == end) {
+ return;
+ }
}
if (*p == '#') {
basePrefix = true;
- if (++p == end) return;
+ if (++p == end) {
+ return;
+ }
}
if (*p == '0') {
enforce(align == Align::DEFAULT, "alignment specified twice");
fill = '0';
align = Align::PAD_AFTER_SIGN;
- if (++p == end) return;
+ if (++p == end) {
+ return;
+ }
}
auto readInt = [&] {
width = kDynamicWidth;
++p;
- if (p == end) return;
+ if (p == end) {
+ return;
+ }
- if (*p >= '0' && *p <= '9') widthIndex = readInt();
+ if (*p >= '0' && *p <= '9') {
+ widthIndex = readInt();
+ }
- if (p == end) return;
+ if (p == end) {
+ return;
+ }
} else if (*p >= '0' && *p <= '9') {
width = readInt();
- if (p == end) return;
+ if (p == end) {
+ return;
+ }
}
if (*p == ',') {
thousandsSeparator = true;
- if (++p == end) return;
+ if (++p == end) {
+ return;
+ }
}
if (*p == '.') {
trailingDot = true;
}
- if (p == end) return;
+ if (p == end) {
+ return;
+ }
}
presentation = *p;
- if (++p == end) return;
+ if (++p == end) {
+ return;
+ }
}
error("extra characters in format string");
uint8_t v = uint8_t(*p);
size_t s = kHeaderSize;
s += 1 + b0key(v);
- if (s > size) return 0;
+ if (s > size) {
+ return 0;
+ }
s += 1 + b1key(v);
- if (s > size) return 1;
+ if (s > size) {
+ return 1;
+ }
s += 1 + b2key(v);
- if (s > size) return 2;
+ if (s > size) {
+ return 2;
+ }
s += 1 + b3key(v);
- if (s > size) return 3;
+ if (s > size) {
+ return 3;
+ }
return 4;
}
uint16_t v = loadUnaligned<uint16_t>(p);
size_t s = kHeaderSize;
s += 1 + b0key(v);
- if (s > size) return 0;
+ if (s > size) {
+ return 0;
+ }
s += 1 + b1key(v);
- if (s > size) return 1;
+ if (s > size) {
+ return 1;
+ }
s += 1 + b2key(v);
- if (s > size) return 2;
+ if (s > size) {
+ return 2;
+ }
s += 1 + b3key(v);
- if (s > size) return 3;
+ if (s > size) {
+ return 3;
+ }
s += 1 + b4key(v);
- if (s > size) return 4;
+ if (s > size) {
+ return 4;
+ }
return 5;
}
}
result_type& operator()() {
- if (!value_) value_ = func_();
+ if (!value_) {
+ value_ = func_();
+ }
return *value_;
}
*/
inline void* checkedMalloc(size_t size) {
void* p = malloc(size);
- if (!p) std::__throw_bad_alloc();
+ if (!p) {
+ std::__throw_bad_alloc();
+ }
return p;
}
inline void* checkedCalloc(size_t n, size_t size) {
void* p = calloc(n, size);
- if (!p) std::__throw_bad_alloc();
+ if (!p) {
+ std::__throw_bad_alloc();
+ }
return p;
}
inline void* checkedRealloc(void* ptr, size_t size) {
void* p = realloc(ptr, size);
- if (!p) std::__throw_bad_alloc();
+ if (!p) {
+ std::__throw_bad_alloc();
+ }
return p;
}
public:
void* allocate(size_t size) {
void* p = ::malloc(size);
- if (!p) throw std::bad_alloc();
+ if (!p) {
+ throw std::bad_alloc();
+ }
return p;
}
void deallocate(void* p) {
}
void operator()(pointer p) const {
- if (!p) return;
+ if (!p) {
+ return;
+ }
const_cast<allocator_delete*>(this)->destroy(p);
const_cast<allocator_delete*>(this)->deallocate(p, 1);
}
mapStart_ = nullptr;
} else {
int flags = options_.shared ? MAP_SHARED : MAP_PRIVATE;
- if (anon) flags |= MAP_ANONYMOUS;
- if (options_.prefault) flags |= MAP_POPULATE;
+ if (anon) {
+ flags |= MAP_ANONYMOUS;
+ }
+ if (options_.prefault) {
+ flags |= MAP_POPULATE;
+ }
// The standard doesn't actually require PROT_NONE to be zero...
int prot = PROT_NONE;
}
void MemoryMapping::munlock(bool dontneed) {
- if (!locked_) return;
+ if (!locked_) {
+ return;
+ }
size_t amountSucceeded = 0;
if (!memOpInChunks(
void lock() {
uint_fast32_t count = 0;
while (!LIKELY(try_lock())) {
- if (++count > 1000) std::this_thread::yield();
+ if (++count > 1000) {
+ std::this_thread::yield();
+ }
}
}
void lock_shared() {
uint_fast32_t count = 0;
while (!LIKELY(try_lock_shared())) {
- if (++count > 1000) std::this_thread::yield();
+ if (++count > 1000) {
+ std::this_thread::yield();
+ }
}
}
void lock_upgrade() {
uint_fast32_t count = 0;
while (!try_lock_upgrade()) {
- if (++count > 1000) std::this_thread::yield();
+ if (++count > 1000) {
+ std::this_thread::yield();
+ }
}
}
void unlock_upgrade_and_lock() {
int64_t count = 0;
while (!try_unlock_upgrade_and_lock()) {
- if (++count > 1000) std::this_thread::yield();
+ if (++count > 1000) {
+ std::this_thread::yield();
+ }
}
}
class ReadHolder {
public:
explicit ReadHolder(RWSpinLock* lock) : lock_(lock) {
- if (lock_) lock_->lock_shared();
+ if (lock_) {
+ lock_->lock_shared();
+ }
}
explicit ReadHolder(RWSpinLock& lock) : lock_(&lock) {
// down-grade
explicit ReadHolder(UpgradedHolder&& upgraded) : lock_(upgraded.lock_) {
upgraded.lock_ = nullptr;
- if (lock_) lock_->unlock_upgrade_and_lock_shared();
+ if (lock_) {
+ lock_->unlock_upgrade_and_lock_shared();
+ }
}
explicit ReadHolder(WriteHolder&& writer) : lock_(writer.lock_) {
writer.lock_ = nullptr;
- if (lock_) lock_->unlock_and_lock_shared();
+ if (lock_) {
+ lock_->unlock_and_lock_shared();
+ }
}
ReadHolder& operator=(ReadHolder&& other) {
ReadHolder(const ReadHolder& other) = delete;
ReadHolder& operator=(const ReadHolder& other) = delete;
- ~ReadHolder() { if (lock_) lock_->unlock_shared(); }
+ ~ReadHolder() {
+ if (lock_) {
+ lock_->unlock_shared();
+ }
+ }
void reset(RWSpinLock* lock = nullptr) {
- if (lock == lock_) return;
- if (lock_) lock_->unlock_shared();
+ if (lock == lock_) {
+ return;
+ }
+ if (lock_) {
+ lock_->unlock_shared();
+ }
lock_ = lock;
- if (lock_) lock_->lock_shared();
+ if (lock_) {
+ lock_->lock_shared();
+ }
}
void swap(ReadHolder* other) {
class UpgradedHolder {
public:
explicit UpgradedHolder(RWSpinLock* lock) : lock_(lock) {
- if (lock_) lock_->lock_upgrade();
+ if (lock_) {
+ lock_->lock_upgrade();
+ }
}
explicit UpgradedHolder(RWSpinLock& lock) : lock_(&lock) {
explicit UpgradedHolder(WriteHolder&& writer) {
lock_ = writer.lock_;
writer.lock_ = nullptr;
- if (lock_) lock_->unlock_and_lock_upgrade();
+ if (lock_) {
+ lock_->unlock_and_lock_upgrade();
+ }
}
UpgradedHolder(UpgradedHolder&& other) noexcept : lock_(other.lock_) {
UpgradedHolder(const UpgradedHolder& other) = delete;
UpgradedHolder& operator =(const UpgradedHolder& other) = delete;
- ~UpgradedHolder() { if (lock_) lock_->unlock_upgrade(); }
+ ~UpgradedHolder() {
+ if (lock_) {
+ lock_->unlock_upgrade();
+ }
+ }
void reset(RWSpinLock* lock = nullptr) {
- if (lock == lock_) return;
- if (lock_) lock_->unlock_upgrade();
+ if (lock == lock_) {
+ return;
+ }
+ if (lock_) {
+ lock_->unlock_upgrade();
+ }
lock_ = lock;
- if (lock_) lock_->lock_upgrade();
+ if (lock_) {
+ lock_->lock_upgrade();
+ }
}
void swap(UpgradedHolder* other) {
class WriteHolder {
public:
explicit WriteHolder(RWSpinLock* lock) : lock_(lock) {
- if (lock_) lock_->lock();
+ if (lock_) {
+ lock_->lock();
+ }
}
explicit WriteHolder(RWSpinLock& lock) : lock_(&lock) {
explicit WriteHolder(UpgradedHolder&& upgraded) {
lock_ = upgraded.lock_;
upgraded.lock_ = nullptr;
- if (lock_) lock_->unlock_upgrade_and_lock();
+ if (lock_) {
+ lock_->unlock_upgrade_and_lock();
+ }
}
WriteHolder(WriteHolder&& other) noexcept : lock_(other.lock_) {
WriteHolder(const WriteHolder& other) = delete;
WriteHolder& operator =(const WriteHolder& other) = delete;
- ~WriteHolder () { if (lock_) lock_->unlock(); }
+ ~WriteHolder() {
+ if (lock_) {
+ lock_->unlock();
+ }
+ }
void reset(RWSpinLock* lock = nullptr) {
- if (lock == lock_) return;
- if (lock_) lock_->unlock();
+ if (lock == lock_) {
+ return;
+ }
+ if (lock_) {
+ lock_->unlock();
+ }
lock_ = lock;
- if (lock_) lock_->lock();
+ if (lock_) {
+ lock_->lock();
+ }
}
void swap(WriteHolder* other) {
bool try_lock() {
RWTicket t;
FullInt old = t.whole = load_acquire(&ticket.whole);
- if (t.users != t.write) return false;
+ if (t.users != t.write) {
+ return false;
+ }
++t.users;
return __sync_bool_compare_and_swap(&ticket.whole, old, t.whole);
}
QuarterInt val = __sync_fetch_and_add(&ticket.users, 1);
while (val != load_acquire(&ticket.write)) {
asm_volatile_pause();
- if (UNLIKELY(++count > 1000)) std::this_thread::yield();
+ if (UNLIKELY(++count > 1000)) {
+ std::this_thread::yield();
+ }
}
}
uint_fast32_t count = 0;
while (!LIKELY(try_lock_shared())) {
asm_volatile_pause();
- if (UNLIKELY((++count & 1023) == 0)) std::this_thread::yield();
+ if (UNLIKELY((++count & 1023) == 0)) {
+ std::this_thread::yield();
+ }
}
}
ReadHolder& operator=(ReadHolder const&) = delete;
explicit ReadHolder(RWSpinLock* lock) : lock_(lock) {
- if (lock_) lock_->lock_shared();
+ if (lock_) {
+ lock_->lock_shared();
+ }
}
explicit ReadHolder(RWSpinLock &lock) : lock_ (&lock) {
- if (lock_) lock_->lock_shared();
+ if (lock_) {
+ lock_->lock_shared();
+ }
}
// atomically unlock the write-lock from writer and acquire the read-lock
}
~ReadHolder() {
- if (lock_) lock_->unlock_shared();
+ if (lock_) {
+ lock_->unlock_shared();
+ }
}
void reset(RWSpinLock *lock = nullptr) {
- if (lock_) lock_->unlock_shared();
+ if (lock_) {
+ lock_->unlock_shared();
+ }
lock_ = lock;
- if (lock_) lock_->lock_shared();
+ if (lock_) {
+ lock_->lock_shared();
+ }
}
void swap(ReadHolder *other) {
WriteHolder& operator=(WriteHolder const&) = delete;
explicit WriteHolder(RWSpinLock* lock) : lock_(lock) {
- if (lock_) lock_->lock();
+ if (lock_) {
+ lock_->lock();
+ }
}
explicit WriteHolder(RWSpinLock &lock) : lock_ (&lock) {
- if (lock_) lock_->lock();
+ if (lock_) {
+ lock_->lock();
+ }
}
~WriteHolder() {
- if (lock_) lock_->unlock();
+ if (lock_) {
+ lock_->unlock();
+ }
}
void reset(RWSpinLock *lock = nullptr) {
- if (lock == lock_) return;
- if (lock_) lock_->unlock();
+ if (lock == lock_) {
+ return;
+ }
+ if (lock_) {
+ lock_->unlock();
+ }
lock_ = lock;
- if (lock_) lock_->lock();
+ if (lock_) {
+ lock_->lock();
+ }
}
void swap(WriteHolder *other) {
if (hex_style) {
hex_append = true;
} else {
- if (c == '\r') output += 'r';
- else if (c == '\n') output += 'n';
- else if (c == '\t') output += 't';
- else if (c == '\a') output += 'a';
- else if (c == '\b') output += 'b';
- else if (c == '\0') output += '0';
- else if (c == '\\') output += '\\';
- else {
+ if (c == '\r') {
+ output += 'r';
+ } else if (c == '\n') {
+ output += 'n';
+ } else if (c == '\t') {
+ output += 't';
+ } else if (c == '\a') {
+ output += 'a';
+ } else if (c == '\b') {
+ output += 'b';
+ } else if (c == '\0') {
+ output += '0';
+ } else if (c == '\\') {
+ output += '\\';
+ } else {
hex_append = true;
}
}
template <class InputString, class OutputString>
bool hexlify(const InputString& input, OutputString& output,
bool append_output) {
- if (!append_output) output.clear();
+ if (!append_output) {
+ output.clear();
+ }
static char hexValues[] = "0123456789abcdef";
auto j = output.size();
}
ProcessReturnCode::State ProcessReturnCode::state() const {
- if (rawStatus_ == RV_NOT_STARTED) return NOT_STARTED;
- if (rawStatus_ == RV_RUNNING) return RUNNING;
- if (WIFEXITED(rawStatus_)) return EXITED;
- if (WIFSIGNALED(rawStatus_)) return KILLED;
+ if (rawStatus_ == RV_NOT_STARTED) {
+ return NOT_STARTED;
+ }
+ if (rawStatus_ == RV_RUNNING) {
+ return RUNNING;
+ }
+ if (WIFEXITED(rawStatus_)) {
+ return EXITED;
+ }
+ if (WIFSIGNALED(rawStatus_)) {
+ return KILLED;
+ }
assume_unreachable();
}
if (argv.empty()) {
throw std::invalid_argument("argv must not be empty");
}
- if (!executable) executable = argv[0].c_str();
+ if (!executable) {
+ executable = argv[0].c_str();
+ }
spawn(cloneStrings(argv), executable, options, env);
}
auto skip = [&] { ++p; return U'\ufffd'; };
if (p >= e) {
- if (skipOnError) return skip();
+ if (skipOnError) {
+ return skip();
+ }
throw std::runtime_error("folly::utf8ToCodePoint empty/invalid string");
}
uint32_t d = fst;
if ((fst & 0xC0) != 0xC0) {
- if (skipOnError) return skip();
+ if (skipOnError) {
+ return skip();
+ }
throw std::runtime_error(to<std::string>("folly::utf8ToCodePoint i=0 d=", d));
}
unsigned char tmp = p[i];
if ((tmp & 0xC0) != 0x80) {
- if (skipOnError) return skip();
+ if (skipOnError) {
+ return skip();
+ }
throw std::runtime_error(
to<std::string>("folly::utf8ToCodePoint i=", i, " tmp=", (uint32_t)tmp));
}
// overlong, could have been encoded with i bytes
if ((d & ~bitMask[i - 1]) == 0) {
- if (skipOnError) return skip();
+ if (skipOnError) {
+ return skip();
+ }
throw std::runtime_error(
to<std::string>("folly::utf8ToCodePoint i=", i, " d=", d));
}
// check for surrogates only needed for 3 bytes
if (i == 2) {
if ((d >= 0xD800 && d <= 0xDFFF) || d > 0x10FFFF) {
- if (skipOnError) return skip();
+ if (skipOnError) {
+ return skip();
+ }
throw std::runtime_error(
to<std::string>("folly::utf8ToCodePoint i=", i, " d=", d));
}
}
}
- if (skipOnError) return skip();
+ if (skipOnError) {
+ return skip();
+ }
throw std::runtime_error("folly::utf8ToCodePoint encoding length maxed out");
}
if (LIKELY(size_t(end - begin) >= kMaxVarintLength64)) { // fast path
int64_t b;
do {
- b = *p++; val = (b & 0x7f) ; if (b >= 0) break;
- b = *p++; val |= (b & 0x7f) << 7; if (b >= 0) break;
- b = *p++; val |= (b & 0x7f) << 14; if (b >= 0) break;
- b = *p++; val |= (b & 0x7f) << 21; if (b >= 0) break;
- b = *p++; val |= (b & 0x7f) << 28; if (b >= 0) break;
- b = *p++; val |= (b & 0x7f) << 35; if (b >= 0) break;
- b = *p++; val |= (b & 0x7f) << 42; if (b >= 0) break;
- b = *p++; val |= (b & 0x7f) << 49; if (b >= 0) break;
- b = *p++; val |= (b & 0x7f) << 56; if (b >= 0) break;
- b = *p++; val |= (b & 0x01) << 63; if (b >= 0) break;
+ b = *p++;
+ val = (b & 0x7f);
+ if (b >= 0) {
+ break;
+ }
+ b = *p++;
+ val |= (b & 0x7f) << 7;
+ if (b >= 0) {
+ break;
+ }
+ b = *p++;
+ val |= (b & 0x7f) << 14;
+ if (b >= 0) {
+ break;
+ }
+ b = *p++;
+ val |= (b & 0x7f) << 21;
+ if (b >= 0) {
+ break;
+ }
+ b = *p++;
+ val |= (b & 0x7f) << 28;
+ if (b >= 0) {
+ break;
+ }
+ b = *p++;
+ val |= (b & 0x7f) << 35;
+ if (b >= 0) {
+ break;
+ }
+ b = *p++;
+ val |= (b & 0x7f) << 42;
+ if (b >= 0) {
+ break;
+ }
+ b = *p++;
+ val |= (b & 0x7f) << 49;
+ if (b >= 0) {
+ break;
+ }
+ b = *p++;
+ val |= (b & 0x7f) << 56;
+ if (b >= 0) {
+ break;
+ }
+ b = *p++;
+ val |= (b & 0x01) << 63;
+ if (b >= 0) {
+ break;
+ }
return makeUnexpected(DecodeVarintError::TooManyBytes);
} while (false);
} else {
T* p_;
counted_ptr() : p_(nullptr) {}
counted_ptr(counted_shared_tag, T* p) : p_(p) {
- if (p_)
+ if (p_) {
counted_ptr_base<Atom>::getRef(p_)->add_ref();
+ }
}
counted_ptr(const counted_ptr& o) : p_(o.p_) {
- if (p_)
+ if (p_) {
counted_ptr_base<Atom>::getRef(p_)->add_ref();
+ }
}
counted_ptr& operator=(const counted_ptr& o) {
if (p_ && counted_ptr_base<Atom>::getRef(p_)->release_ref() == 1) {
free(counted_ptr_base<Atom>::getRef(p_));
}
p_ = o.p_;
- if (p_)
+ if (p_) {
counted_ptr_base<Atom>::getRef(p_)->add_ref();
+ }
return *this;
}
explicit counted_ptr(T* p) : p_(p) {
});
}
- for (auto& t : threads)
+ for (auto& t : threads) {
t.join();
}
+}
void benchmarkSharedPtrCopy(size_t numThreads, size_t iters) {
auto p = std::make_shared<int>(1);
void dynamic::destroy() noexcept {
// This short-circuit speeds up some microbenchmarks.
- if (type_ == NULLT) return;
+ if (type_ == NULLT) {
+ return;
+ }
#define FB_X(T) detail::Destroy::destroy(getAddress<T>())
FB_DYNAMIC_APPLY(type_, FB_X);
std::thread producer1([&] {
++turn;
- while (turn < 4)
+ while (turn < 4) {
;
+ }
++turn;
q.add(SlowMover(true));
});
std::thread producer2([&] {
++turn;
- while (turn < 5)
+ while (turn < 5) {
;
+ }
q.add(SlowMover(false));
});
if (kUnchecked || LIKELY(position() + n < size_)) {
if (LIKELY(n < kLinearScanThreshold)) {
- for (SizeType i = 0; i < n; ++i)
+ for (SizeType i = 0; i < n; ++i) {
upper_.next();
+ }
} else {
upper_.skip(n);
}
while (true) {
value_ = readLowerPart(upper_.position()) |
(upper_.value() << numLowerBits_);
- if (LIKELY(value_ >= value)) break;
+ if (LIKELY(value_ >= value)) {
+ break;
+ }
upper_.next();
}
}
template <class Condition>
void EventCount::await(Condition condition) {
- if (condition()) return; // fast path
+ if (condition()) {
+ return; // fast path
+ }
// condition() is the only thing that may throw, everything else is
// noexcept, so we can hoist the try/catch block outside of the loop
started.fetch_add(1);
Rec* myrec = (combining && tc) ? ex.allocRec() : nullptr;
uint64_t sum = 0;
- while (!start.load())
+ while (!start.load()) {
;
+ }
if (!combining) {
// no combining
});
}
- while (started.load() < nthreads)
+ while (started.load() < nthreads) {
;
+ }
auto tbegin = std::chrono::steady_clock::now();
// begin time measurement
for (int tid = 0; tid < nthreads; ++tid) {
threads[tid] = std::thread([&, tid] {
started.fetch_add(1);
- while (!start.load())
+ while (!start.load()) {
/* spin */;
+ }
fn(tid);
});
}
- while (started.load() < nthreads)
+ while (started.load() < nthreads) {
/* spin */;
+ }
// begin time measurement
auto tbegin = std::chrono::steady_clock::now();
void push(T val) {
DEBUG_PRINT(this);
auto pnode = new Node(val, head_.load());
- while (!head_.compare_exchange_weak(pnode->next_, pnode));
+ while (!head_.compare_exchange_weak(pnode->next_, pnode)) {
+ ;
+ }
}
bool pop(T& val) {
hazptr_holder hptr;
Node* pnode = head_.load();
do {
- if (pnode == nullptr)
+ if (pnode == nullptr) {
return false;
- if (!hptr.try_protect(pnode, head_))
+ }
+ if (!hptr.try_protect(pnode, head_)) {
continue;
+ }
auto next = pnode->next_;
- if (head_.compare_exchange_weak(pnode, next)) break;
+ if (head_.compare_exchange_weak(pnode, next)) {
+ break;
+ }
} while (true);
hptr.reset();
val = pnode->value_;
void locate_lower_bound(const T& v, std::atomic<Node*>*& prev) const {
auto curr = prev->load(std::memory_order_relaxed);
while (curr) {
- if (curr->elem_ >= v) break;
+ if (curr->elem_ >= v) {
+ break;
+ }
prev = &(curr->next_);
curr = curr->next_.load(std::memory_order_relaxed);
}
auto prev = &head_;
locate_lower_bound(v, prev);
auto curr = prev->load(std::memory_order_relaxed);
- if (curr && curr->elem_ == v) return false;
+ if (curr && curr->elem_ == v) {
+ return false;
+ }
prev->store(new Node(std::move(v), curr));
return true;
}
auto prev = &head_;
locate_lower_bound(v, prev);
auto curr = prev->load(std::memory_order_relaxed);
- if (!curr || curr->elem_ != v) return false;
+ if (!curr || curr->elem_ != v) {
+ return false;
+ }
Node *curr_next = curr->next_.load();
// Patch up the actual list...
prev->store(curr_next, std::memory_order_release);
auto curr = prev->load(std::memory_order_acquire);
while (true) {
if (!curr) { return false; }
- if (!hptr_curr->try_protect(curr, *prev))
+ if (!hptr_curr->try_protect(curr, *prev)) {
break;
+ }
auto next = curr->next_.load(std::memory_order_acquire);
- if (prev->load(std::memory_order_acquire) != curr)
+ if (prev->load(std::memory_order_acquire) != curr) {
break;
+ }
if (curr->elem_ == val) {
return true;
} else if (!(curr->elem_ < val)) {
do {
p = hptr.get_protected(p_);
if (p->val_ != u) { delete n; return false; }
- if (p_.compare_exchange_weak(p, n)) break;
+ if (p_.compare_exchange_weak(p, n)) {
+ break;
+ }
} while (true);
hptr.reset();
p->retire();
p->active_.store(true, std::memory_order_relaxed);
p->next_ = hazptrs_.load(std::memory_order_acquire);
while (!hazptrs_.compare_exchange_weak(
- p->next_, p, std::memory_order_release, std::memory_order_acquire))
+ p->next_, p, std::memory_order_release, std::memory_order_acquire)) {
/* keep trying */;
+ }
auto hcount = hcount_.fetch_add(1);
DEBUG_PRINT(this << " " << p << " " << sizeof(hazptr_rec) << " " << hcount);
return p;
Reader reader(list);
for (size_t i = 0, j = 0; i < iters; ++i, ++j) {
- if (j == order.size()) j = 0;
+ if (j == order.size()) {
+ j = 0;
+ }
reader.jump(order[j]);
folly::doNotOptimizeAway(reader.value());
}
Reader reader(list);
for (size_t i = 0, j = 0; i < iters; ++i, ++j) {
- if (j == order.size()) j = 0;
+ if (j == order.size()) {
+ j = 0;
+ }
reader.jumpTo(data[order[j]]);
folly::doNotOptimizeAway(reader.value());
}
for (uint32_t tid = 0; tid < nthreads; ++tid) {
threads[tid] = std::thread([&, tid] {
started.fetch_add(1);
- while (!start.load())
+ while (!start.load()) {
/* nothing */;
+ }
fn(tid);
});
}
- while (started.load() < nthreads)
+ while (started.load() < nthreads) {
/* nothing */;
+ }
auto tbegin = std::chrono::steady_clock::now();
// begin time measurement
template <class T>
void SemiFuture<T>::throwIfInvalid() const {
- if (!core_)
+ if (!core_) {
throwNoState();
}
+}
template <class T>
Optional<Try<T>> SemiFuture<T>::poll() {
template <class FutureType, typename T = typename FutureType::value_type>
void waitImpl(FutureType& f) {
// short-circuit if there's nothing to do
- if (f.isReady()) return;
+ if (f.isReady()) {
+ return;
+ }
FutureBatonType baton;
f.setCallback_([&](const Try<T>& /* t */) { baton.post(); });
// Set callback so to ensure that the via executor has something on it
// so that once the preceding future triggers this callback, drive will
// always have a callback to satisfy it
- if (f.isReady())
+ if (f.isReady()) {
return;
+ }
f = f.via(e).then([](T&& t) { return std::move(t); });
while (!f.isReady()) {
e->drive();
while (!scheduledFuncs_.empty()) {
auto& sf = scheduledFuncs_.top();
- if (sf.time > now_)
+ if (sf.time > now_) {
break;
+ }
funcs_.emplace(sf.moveOutFunc());
scheduledFuncs_.pop();
}
while (true) {
{
std::lock_guard<std::mutex> lock(lock_);
- if (!funcs_.empty())
+ if (!funcs_.empty()) {
break;
+ }
}
sem_.wait();
bool operator<(ScheduledFunc const& b) const {
// Earlier-scheduled things must be *higher* priority
// in the max-based std::priority_queue
- if (time == b.time)
+ if (time == b.time) {
return ordinal > b.ordinal;
+ }
return time > b.time;
}
template <class T>
void Promise<T>::detach() {
if (core_) {
- if (!retrieved_)
+ if (!retrieved_) {
core_->detachFuture();
+ }
core_->detachPromise();
core_ = nullptr;
}
BENCHMARK_SUSPEND {
folly::Baton<> b1, b2;
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
consumer = std::thread([&]{
b1.post();
- for (auto& f : futures) f.then(incr<int>);
+ for (auto& f : futures) {
+ f.then(incr<int>);
+ }
});
consumer.join();
producer = std::thread([&]{
b2.post();
- for (auto& p : promises) p.setValue(42);
+ for (auto& p : promises) {
+ p.setValue(42);
+ }
});
b1.wait();
BENCHMARK_SUSPEND {
folly::Baton<> b1, b2;
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
consumer = std::thread([&]{
b1.post();
std::vector<Promise<int>> promises(10);
std::vector<Future<int>> futures;
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
auto allf = collectAll(futures);
std::vector<Promise<int>> promises(4);
std::vector<Future<int>> futures;
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
auto allf = collectAll(futures);
std::vector<Promise<Unit>> promises(10);
std::vector<Future<Unit>> futures;
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
- auto allf = collectAll(futures)
- .then([](Try<std::vector<Try<Unit>>>&& ts) {
- for (auto& f : ts.value())
- f.value();
- });
+ auto allf = collectAll(futures).then([](Try<std::vector<Try<Unit>>>&& ts) {
+ for (auto& f : ts.value()) {
+ f.value();
+ }
+ });
std::shuffle(promises.begin(), promises.end(), rng);
- for (auto& p : promises)
+ for (auto& p : promises) {
p.setValue();
+ }
EXPECT_TRUE(allf.isReady());
}
}
std::vector<Promise<int>> promises(10);
std::vector<Future<int>> futures;
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
auto allf = collect(futures);
std::vector<Promise<int>> promises(10);
std::vector<Future<int>> futures;
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
auto allf = collect(futures);
std::vector<Promise<Unit>> promises(10);
std::vector<Future<Unit>> futures;
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
auto allf = collect(futures);
std::vector<Promise<Unit>> promises(10);
std::vector<Future<Unit>> futures;
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
auto allf = collect(futures);
std::vector<Promise<std::unique_ptr<int>>> promises(10);
std::vector<Future<std::unique_ptr<int>>> futures;
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
collect(futures);
}
std::iota(indices.begin(), indices.end(), 0);
std::shuffle(indices.begin(), indices.end(), rng);
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
auto allf = collect(futures);
std::vector<Promise<int>> promises(10);
std::vector<Future<int>> futures;
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
for (auto& f : futures) {
EXPECT_FALSE(f.isReady());
std::vector<Promise<Unit>> promises(10);
std::vector<Future<Unit>> futures;
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
for (auto& f : futures) {
EXPECT_FALSE(f.isReady());
std::vector<Promise<int>> promises(10);
std::vector<Future<int>> futures;
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
auto anyf = collectAny(futures)
.then([](std::pair<size_t, Try<int>> p) {
TEST(Collect, alreadyCompleted) {
{
std::vector<Future<Unit>> fs;
- for (int i = 0; i < 10; i++)
+ for (int i = 0; i < 10; i++) {
fs.push_back(makeFuture());
+ }
collectAll(fs)
.then([&](std::vector<Try<Unit>> ts) {
}
{
std::vector<Future<int>> fs;
- for (int i = 0; i < 10; i++)
+ for (int i = 0; i < 10; i++) {
fs.push_back(makeFuture(i));
+ }
collectAny(fs)
.then([&](std::pair<size_t, Try<int>> p) {
std::vector<Promise<Unit>> promises(10);
std::vector<Future<Unit>> futures;
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
bool flag = false;
size_t n = 3;
.then([&](std::vector<std::pair<size_t, Try<Unit>>> v) {
flag = true;
EXPECT_EQ(n, v.size());
- for (auto& tt : v)
+ for (auto& tt : v) {
EXPECT_TRUE(tt.second.hasValue());
+ }
});
promises[0].setValue();
{
folly::small_vector<Future<Unit>> futures;
- for (int i = 0; i < 10; i++)
+ for (int i = 0; i < 10; i++) {
futures.push_back(makeFuture());
+ }
auto anyf = collectAny(futures);
}
{
folly::small_vector<Future<Unit>> futures;
- for (int i = 0; i < 10; i++)
+ for (int i = 0; i < 10; i++) {
futures.push_back(makeFuture());
+ }
auto allf = collectAll(futures);
}
};
// keep retrying until success (like a cas)
- while (!tryTransition()) ;
+ while (!tryTransition()) {
+ ;
+ }
EXPECT_EQ(State::B, fsm.getState());
EXPECT_EQ(1, count);
EXPECT_EQ(0, unprotectedCount);
- while (!tryTransition()) ;
+ while (!tryTransition()) {
+ ;
+ }
EXPECT_EQ(State::A, fsm.getState());
EXPECT_EQ(0, count);
EXPECT_EQ(-1, unprotectedCount);
{
t = std::thread([=] {
ManualWaiter eastWaiter(eastExecutor);
- while (!done)
+ while (!done) {
eastWaiter.drive();
+ }
});
}
p.setValue();
});
- while (!done) x.run();
+ while (!done) {
+ x.run();
+ }
t1.join();
t2.join();
}
| map([](int n) {
return GENERATOR(int) {
int i;
- for (i = 1; i < n; ++i)
+ for (i = 1; i < n; ++i) {
yield(i);
- for (; i >= 1; --i)
+ }
+ for (; i >= 1; --i) {
yield(i);
+ }
};
})
| concat;
{
m_a = 0xdeadbeef;
m_b = m_c = m_d = seed;
- for (int i=0; i<20; ++i)
- (void)Value();
+ for (int i = 0; i < 20; ++i) {
+ (void)Value();
+ }
}
private:
for (int m=0; m<MEASURES; ++m)
{
counter[m][l] |= measure[m][l];
- if (~counter[m][l]) done = 0;
+ if (~counter[m][l]) {
+ done = 0;
+ }
}
}
- if (done) break;
+ if (done) {
+ break;
+ }
}
if (k == TRIES)
{
{
m_a = 0xdeadbeef;
m_b = m_c = m_d = seed;
- for (int i=0; i<20; ++i)
- (void)Value();
+ for (int i = 0; i < 20; ++i) {
+ (void)Value();
+ }
}
private:
for (int m=0; m<MEASURES; ++m)
{
counter[m][l] |= measure[m][l];
- if (~counter[m][l]) done = 0;
+ if (~counter[m][l]) {
+ done = 0;
+ }
}
}
- if (done) break;
+ if (done) {
+ break;
+ }
}
if (k == TRIES)
{
private:
IOBuf* tailBuf() const {
- if (UNLIKELY(!head_)) return nullptr;
+ if (UNLIKELY(!head_)) {
+ return nullptr;
+ }
IOBuf* buf = head_->prev();
return LIKELY(!buf->isSharedOne()) ? buf : nullptr;
}
int old_flags = fcntl(fd, F_GETFD, 0);
// If reading the flags failed, return error indication now
- if (old_flags < 0)
+ if (old_flags < 0) {
return -1;
+ }
// Set just the flag we want to set
int new_flags;
- if (value != 0)
+ if (value != 0) {
new_flags = old_flags | FD_CLOEXEC;
- else
+ } else {
new_flags = old_flags & ~FD_CLOEXEC;
+ }
// Store modified flag word in the descriptor
return fcntl(fd, F_SETFD, new_flags);
}
void AsyncSocket::doClose() {
- if (fd_ == -1) return;
+ if (fd_ == -1) {
+ return;
+ }
if (const auto shutdownSocketSet = wShutdownSocketSet_.lock()) {
shutdownSocketSet->close(fd_);
} else {
th.join();
}
size_t sum = 0;
- for (auto& atom : atoms) sum += *atom;
+ for (auto& atom : atoms) {
+ sum += *atom;
+ }
EXPECT_EQ(c, sum);
}
template <class Iterator>
int distance_if_multipass(Iterator first, Iterator last) {
typedef typename std::iterator_traits<Iterator>::iterator_category categ;
- if (std::is_same<categ,std::input_iterator_tag>::value)
+ if (std::is_same<categ, std::input_iterator_tag>::value) {
return -1;
+ }
return std::distance(first, last);
}
iterator find(const key_type& key) {
iterator it = lower_bound(key);
- if (it == end() || !key_comp()(key, *it))
+ if (it == end() || !key_comp()(key, *it)) {
return it;
+ }
return end();
}
const_iterator find(const key_type& key) const {
const_iterator it = lower_bound(key);
- if (it == end() || !key_comp()(key, *it))
+ if (it == end() || !key_comp()(key, *it)) {
return it;
+ }
return end();
}
iterator find(const key_type& key) {
iterator it = lower_bound(key);
- if (it == end() || !key_comp()(key, it->first))
+ if (it == end() || !key_comp()(key, it->first)) {
return it;
+ }
return end();
}
const_iterator find(const key_type& key) const {
const_iterator it = lower_bound(key);
- if (it == end() || !key_comp()(key, it->first))
+ if (it == end() || !key_comp()(key, it->first)) {
return it;
+ }
return end();
}
});
}
- for (auto& t : threads) t.join();
+ for (auto& t : threads) {
+ t.join();
+}
}
T *allocate(size_t n) {
void *p = mmap(nullptr, n * sizeof(T), PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
- if (p == MAP_FAILED) throw std::bad_alloc();
+ if (p == MAP_FAILED) {
+ throw std::bad_alloc();
+ }
return (T *)p;
}
struct HashTraits {
size_t operator()(char* a) {
size_t result = 0;
- while (a[0] != 0) result += static_cast<size_t>(*(a++));
+ while (a[0] != 0) {
+ result += static_cast<size_t>(*(a++));
+ }
return result;
}
size_t operator()(const char& a) {
}
size_t operator()(const StringPiece a) {
size_t result = 0;
- for (const auto& ch : a) result += static_cast<size_t>(ch);
+ for (const auto& ch : a) {
+ result += static_cast<size_t>(ch);
+ }
return result;
}
};
struct HashTraits {
size_t operator()(const char* a) {
size_t result = 0;
- while (a[0] != 0) result += static_cast<size_t>(*(a++));
+ while (a[0] != 0) {
+ result += static_cast<size_t>(*(a++));
+ }
return result;
}
size_t operator()(const char& a) {
}
size_t operator()(const StringPiece a) {
size_t result = 0;
- for (const auto& ch : a) result += static_cast<size_t>(ch);
+ for (const auto& ch : a) {
+ result += static_cast<size_t>(ch);
+ }
return result;
}
};
int currentLevel;
do {
currentLevel = insertedLevel.load(std::memory_order_acquire);
- if (currentLevel == kTestEraseInsertions) currentLevel += lag + 1;
+ if (currentLevel == kTestEraseInsertions) {
+ currentLevel += lag + 1;
+ }
} while (currentLevel - lag < i);
KeyT key = randomizeKey(i);
void* atomicHashArrayInsertRaceThread(void* /* j */) {
AHA* arr = atomicHashArrayInsertRaceArray.get();
uintptr_t numInserted = 0;
- while (!runThreadsCreatedAllThreads.load());
+ while (!runThreadsCreatedAllThreads.load()) {
+ ;
+ }
for (int i = 0; i < 2; i++) {
if (arr->insert(RecordT(randomizeKey(i), 0)).first != arr->end()) {
numInserted++;
numOpsPerThread = iters / FLAGS_numThreads;
runThreads([](void* jj) -> void* {
int64_t j = (int64_t) jj;
- while (!runThreadsCreatedAllThreads.load());
+ while (!runThreadsCreatedAllThreads.load()) {
+ ;
+ }
for (int i = 0; i < numOpsPerThread; ++i) {
KeyT key = i + j * numOpsPerThread * 100;
folly::doNotOptimizeAway(globalAHM->find(key) == globalAHM->end());
numOpsPerThread = iters / FLAGS_numThreads;
runThreads([](void* jj) -> void* {
int64_t j = (int64_t) jj;
- while (!runThreadsCreatedAllThreads.load());
+ while (!runThreadsCreatedAllThreads.load()) {
+ ;
+ }
for (int i = 0; i < numOpsPerThread; ++i) {
KeyT key = i + j * numOpsPerThread * 100;
folly::doNotOptimizeAway(globalQPAHM->find(key) == globalQPAHM->end());
numOpsPerThread = iters / FLAGS_numThreads;
runThreads([](void* jj) -> void* {
int64_t j = (int64_t) jj;
- while (!runThreadsCreatedAllThreads.load());
+ while (!runThreadsCreatedAllThreads.load()) {
+ ;
+ }
for (int i = 0; i < numOpsPerThread; ++i) {
if (i % 128) { // ~1% insert mix
KeyT key = randomizeKey(i + j * numOpsPerThread);
numOpsPerThread = iters / FLAGS_numThreads;
runThreads([](void* jj) -> void* {
int64_t j = (int64_t) jj;
- while (!runThreadsCreatedAllThreads.load());
+ while (!runThreadsCreatedAllThreads.load()) {
+ ;
+ }
for (int i = 0; i < numOpsPerThread; ++i) {
if (i % 128) { // ~1% insert mix
KeyT key = randomizeKey(i + j * numOpsPerThread);
numOpsPerThread = iters / FLAGS_numThreads;
runThreads([](void* jj) -> void* {
int64_t j = (int64_t) jj;
- while (!runThreadsCreatedAllThreads.load());
+ while (!runThreadsCreatedAllThreads.load()) {
+ ;
+ }
for (int i = 0; i < numOpsPerThread; ++i) {
KeyT key = randomizeKey(i + j * numOpsPerThread);
folly::doNotOptimizeAway(globalAHA->find(key)->second);
numOpsPerThread = iters / FLAGS_numThreads;
runThreads([](void* jj) -> void* {
int64_t j = (int64_t) jj;
- while (!runThreadsCreatedAllThreads.load());
+ while (!runThreadsCreatedAllThreads.load()) {
+ ;
+ }
for (int i = 0; i < numOpsPerThread; ++i) {
KeyT key = randomizeKey(i + j * numOpsPerThread);
folly::doNotOptimizeAway(globalAHM->find(key)->second);
numOpsPerThread = iters / FLAGS_numThreads;
runThreads([](void* jj) -> void* {
int64_t j = (int64_t) jj;
- while (!runThreadsCreatedAllThreads.load());
+ while (!runThreadsCreatedAllThreads.load()) {
+ ;
+ }
for (int i = 0; i < numOpsPerThread; ++i) {
KeyT key = randomizeKey(i + j * numOpsPerThread);
folly::doNotOptimizeAway(globalQPAHM->find(key)->second);
auto iter = a_set.begin();
for (int i = 0; i < iters; ++i) {
sum += *iter++;
- if (iter == a_set.end()) iter = a_set.begin();
+ if (iter == a_set.end()) {
+ iter = a_set.begin();
+ }
}
BENCHMARK_SUSPEND {
// VLOG(20) << "sum = " << sum;
auto iter = skipList.begin();
for (int i = 0; i < iters; ++i) {
sum += *iter++;
- if (iter == skipList.end()) iter = skipList.begin();
+ if (iter == skipList.end()) {
+ iter = skipList.begin();
+ }
}
BENCHMARK_SUSPEND {
int64_t mergedSum = 0;
FOR_EACH(it, a_set) {
- if (b_set.find(*it) != b_set.end()) mergedSum += *it;
+ if (b_set.find(*it) != b_set.end()) {
+ mergedSum += *it;
+ }
}
BENCHMARK_SUSPEND {
// VLOG(20) << mergedSum;
SkipListType::Skipper skipper(skipList2);
FOR_EACH(it, skipList) {
- if (skipper.to(*it)) mergedSum += *it;
+ if (skipper.to(*it)) {
+ mergedSum += *it;
+ }
}
BENCHMARK_SUSPEND {
for (int i = 0; i < FLAGS_num_sets; ++i) {
locks_[i] = new RWSpinLock();
- if (i > 0) sets_[i] = sets_[0];
+ if (i > 0) {
+ sets_[i] = sets_[0];
+ }
}
// This requires knowledge of the C++ library internals. Only use it if we're
int64_t sum = 0;
SkipListAccessor::Skipper skipper(skipList);
FOR_EACH(it, *values) {
- if (skipper.to(*it)) sum += *it;
+ if (skipper.to(*it)) {
+ sum += *it;
+ }
}
VLOG(20) << "sum = " << sum;
}
struct UniquePtrComp {
bool operator ()(
const std::unique_ptr<int> &x, const std::unique_ptr<int> &y) const {
- if (!x) return false;
- if (!y) return true;
+ if (!x) {
+ return false;
+ }
+ if (!y) {
+ return true;
+ }
return *x < *y;
}
};
EXPECT_EQ(test, s2);
// Constructor from other iterators
std::list<char> lst;
- for (auto c : test) lst.push_back(c);
+ for (auto c : test) {
+ lst.push_back(c);
+ }
String s3(lst.begin(), lst.end());
EXPECT_EQ(test, s3);
// Constructor from wchar_t iterators
std::list<wchar_t> lst1;
- for (auto c : test) lst1.push_back(c);
+ for (auto c : test) {
+ lst1.push_back(c);
+ }
String s4(lst1.begin(), lst1.end());
EXPECT_EQ(test, s4);
// Constructor from wchar_t pointers
// exercise empty
string empty("empty");
string notempty("not empty");
- if (test.empty()) test = String(empty.begin(), empty.end());
- else test = String(notempty.begin(), notempty.end());
+ if (test.empty()) {
+ test = String(empty.begin(), empty.end());
+ } else {
+ test = String(notempty.begin(), notempty.end());
+ }
}
template <class String> void clause11_21_4_5(String & test) {
String s;
randomString(&s, maxString);
int tristate = test.compare(s);
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
+ if (tristate > 0) {
+ tristate = 1;
+ } else if (tristate < 0) {
+ tristate = 2;
+ }
Num2String(test, tristate);
}
random(0, test.size()),
random(0, test.size()),
s);
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
+ if (tristate > 0) {
+ tristate = 1;
+ } else if (tristate < 0) {
+ tristate = 2;
+ }
Num2String(test, tristate);
}
str,
random(0, str.size()),
random(0, str.size()));
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
+ if (tristate > 0) {
+ tristate = 1;
+ } else if (tristate < 0) {
+ tristate = 2;
+ }
Num2String(test, tristate);
}
String s;
randomString(&s, maxString);
int tristate = test.compare(s.c_str());
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- Num2String(test, tristate);
+ if (tristate > 0) {
+ tristate = 1;
+ } else if (tristate < 0) {
+ tristate = 2;
+ }
+ Num2String(test, tristate);
}
template <class String> void clause11_21_4_7_9_e(String & test) {
random(0, test.size()),
str.c_str(),
random(0, str.size()));
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
+ if (tristate > 0) {
+ tristate = 1;
+ } else if (tristate < 0) {
+ tristate = 2;
+ }
Num2String(test, tristate);
}
void(*f_fbstring)(folly::fbstring&),
void(*f_wfbstring)(folly::basic_fbstring<wchar_t>&)) {
do {
- if (1) {} else EXPECT_TRUE(1) << "Testing clause " << clause;
+ if (1) {
+ } else {
+ EXPECT_TRUE(1) << "Testing clause " << clause;
+ }
randomString(&r);
c = r;
EXPECT_EQ(c, r);
auto mbv = std::vector<char>(wret + 1);
auto mb = mbv.data();
int ret = wcstombs(mb, wc.c_str(), wret + 1);
- if (ret == wret) mb[wret] = '\0';
+ if (ret == wret) {
+ mb[wret] = '\0';
+ }
const char *mc = c.c_str();
std::string one(mb);
std::string two(mc);
void BENCHFUN(ctorFromTwoPointers)(size_t iters, size_t arg) {
/* library-local */ static STRING s;
BENCHMARK_SUSPEND {
- if (s.size() < arg) s.resize(arg);
+ if (s.size() < arg) {
+ s.resize(arg);
+ }
}
FOR_EACH_RANGE (i, 0, iters) {
STRING s1(s.begin(), s.end());
EXPECT_EQ(v.size(), lst.size() / 2);
j = 0;
FOR_EACH (i, lst) {
- if (j == v.size()) break;
+ if (j == v.size()) {
+ break;
+ }
EXPECT_EQ(v[j], *i);
j++;
}
auto const obj1 = randomObject<VECTOR::value_type>();
VECTOR v(random(0U, 100U), obj1);
FOR_EACH_RANGE (i, 0, iters) {
- if (v.empty()) continue;
+ if (v.empty()) {
+ continue;
+ }
v.erase(v.begin());
}
}
std::size_t count = 0u;
auto i = s.rbegin();
for( ; i != s.rend(); ++i, --i, i++, i--, i+=1, i-=1, i+=1 ) {
- if (' ' == *i)
+ if (' ' == *i) {
++count;
+ }
}
return count;
}
sumAA += aa;
sumIter += *iter;
++numIterations;
- if (aa == 1) break;
+ if (aa == 1) {
+ break;
+ }
}
EXPECT_EQ(sumAA, 1); // 0 + 1
EXPECT_EQ(sumIter, 3); // 1 + 2
for (auto i = 0; i < nthreads; ++i) {
thr[i] = std::thread([&]() {
started.fetch_add(1);
- while (!start.load())
+ while (!start.load()) {
;
+ }
for (auto j = 0; j < count; ++j) {
uint32_t idx = pool.allocIndex();
if (idx != 0) {
});
}
- while (started.load() < nthreads)
+ while (started.load() < nthreads) {
;
+ }
start.store(true);
for (auto& t : thr) {
sleep(5);
stop.store(true, std::memory_order_release);
- for (auto& t : threads) t.join();
+ for (auto& t : threads) {
+ t.join();
+ }
LOG(INFO) << "reads: " << reads.load(std::memory_order_acquire)
<< "; writes: " << writes.load(std::memory_order_acquire)
v->push_back(2 * threadIdx);
// Aaand test the TIMED_SYNCHRONIZED macro
- for (;;)
+ for (;;) {
TIMED_SYNCHRONIZED(5, lv, v) {
if (lv) {
// Sleep for a random time to ensure we trigger timeouts
++(*numTimeouts.contextualLock());
}
+ }
};
static const size_t numThreads = 100;
template <typename T, typename... Args>
void testIsRelocatable(Args&&... args) {
- if (!IsRelocatable<T>::value) return;
+ if (!IsRelocatable<T>::value) {
+ return;
+ }
// We use placement new on zeroed memory to avoid garbage subsections
char vsrc[sizeof(T)] = { 0 };
void check_invariant(Container& c) {
auto it = c.begin();
auto end = c.end();
- if (it == end)
+ if (it == end) {
return;
+ }
auto prev = it;
++it;
for (; it != end; ++it, ++prev) {
TEST(SortedVectorTypes, CustomCompare) {
sorted_vector_set<int,less_invert<int> > s;
- for (int i = 0; i < 200; ++i)
+ for (int i = 0; i < 200; ++i) {
s.insert(i);
+ }
check_invariant(s);
sorted_vector_map<int,float,less_invert<int> > m;
- for (int i = 0; i < 200; ++i)
+ for (int i = 0; i < 200; ++i) {
m[i] = 12.0;
+ }
check_invariant(m);
}
// Master verifier
template <class Vector>
void verify(int extras) {
- if (!is_arithmetic<typename Vector::value_type>::value)
+ if (!is_arithmetic<typename Vector::value_type>::value) {
ASSERT_EQ(0 + extras, getTotal()) << "there exist Data but no vectors";
+ }
isSane();
- if (::testing::Test::HasFatalFailure()) return;
- if (customAllocator<Vector>::value) verifyAllocator(0, 0);
+ if (::testing::Test::HasFatalFailure()) {
+ return;
+ }
+ if (customAllocator<Vector>::value) {
+ verifyAllocator(0, 0);
+ }
}
template <class Vector>
void verify(int extras, const Vector& v) {
verifyVector(v);
- if (!is_arithmetic<typename Vector::value_type>::value)
+ if (!is_arithmetic<typename Vector::value_type>::value) {
ASSERT_EQ(v.size() + extras, getTotal())
<< "not all Data are in the vector";
+ }
isSane();
- if (::testing::Test::HasFatalFailure()) return;
- if (customAllocator<Vector>::value) verifyAllocator(v.size(), v.capacity());
+ if (::testing::Test::HasFatalFailure()) {
+ return;
+ }
+ if (customAllocator<Vector>::value) {
+ verifyAllocator(v.size(), v.capacity());
+ }
}
template <class Vector>
void verify(int extras, const Vector& v1, const Vector& v2) {
size += v2.size();
cap += v2.capacity();
}
- if (!is_arithmetic<typename Vector::value_type>::value)
+ if (!is_arithmetic<typename Vector::value_type>::value) {
ASSERT_EQ(size + extras, getTotal()) << "not all Data are in the vector(s)";
+ }
isSane();
- if (::testing::Test::HasFatalFailure()) return;
- if (customAllocator<Vector>::value) verifyAllocator(size, cap);
+ if (::testing::Test::HasFatalFailure()) {
+ return;
+ }
+ if (customAllocator<Vector>::value) {
+ verifyAllocator(size, cap);
+ }
}
//=============================================================================
}
bool operator==(const DataState& o) const {
- if (size_ != o.size_) return false;
+ if (size_ != o.size_) {
+ return false;
+ }
for (size_type i = 0; i < size_; ++i) {
- if (data_[i] != o.data_[i]) return false;
+ if (data_[i] != o.data_[i]) {
+ return false;
+ }
}
return true;
}
STL_TEST("23.2.1-7", ilAllocConstruction, is_arithmetic, m) {
// gcc fail
- if (Ticker::TicksLeft >= 0) return;
+ if (Ticker::TicksLeft >= 0) {
+ return;
+ }
const auto& cm = m;
ASSERT_TRUE(Allocator() == u.get_allocator());
ASSERT_EQ(n, u.size()) << "Vector(n, t).size() != n" << endl;
- for (const auto& val : u) ASSERT_EQ(convertToInt(t), convertToInt(val))
- << "not all elements of Vector(n, t) are equal to t";
+ for (const auto& val : u) {
+ ASSERT_EQ(convertToInt(t), convertToInt(val))
+ << "not all elements of Vector(n, t) are equal to t";
+ }
}
STL_TEST("23.2.3 Table 100.2", forwardIteratorConstruction,
ASSERT_LE(Counter::CountTotalOps, j-i);
ASSERT_EQ(j - i, u.size()) << "u(i,j).size() != j-i";
- for (auto it = u.begin(); it != u.end(); ++it, ++i)
+ for (auto it = u.begin(); it != u.end(); ++it, ++i) {
ASSERT_EQ(*i, convertToInt(*it)) << "u(i,j) constructed incorrectly";
}
+}
STL_TEST("23.2.3 Table 100.2", inputIteratorConstruction,
is_move_constructible, i, j) {
ASSERT_TRUE(Allocator() == u.get_allocator());
ASSERT_EQ(j - i, u.size()) << "u(i,j).size() != j-i";
- for (auto it = u.begin(); it != u.end(); ++it, ++i)
+ for (auto it = u.begin(); it != u.end(); ++it, ++i) {
ASSERT_EQ(*i, convertToInt(*it)) << "u(i,j) constructed incorrectly";
}
+}
STL_TEST("23.2.3 Table 100.3", ilConstruction, is_arithmetic) {
// whitebox: ensure that Vector(il) is implemented in terms of
// Vector(il.begin(), il.end())
// gcc fail
- if (Ticker::TicksLeft >= 0) return;
+ if (Ticker::TicksLeft >= 0) {
+ return;
+ }
Vector u = { 1, 4, 7 };
ASSERT_EQ(3, u.size()) << "u(il).size() fail";
int i = 1;
auto it = u.begin();
- for (; it != u.end(); ++it, i += 3)
+ for (; it != u.end(); ++it, i += 3) {
ASSERT_EQ(i, convertToInt(*it)) << "u(il) constructed incorrectly";
}
+}
STL_TEST("23.2.3 Table 100.4", ilAssignment,
is_arithmetic, a) {
// assign(il.begin(), il.end())
// gcc fail
- if (Ticker::TicksLeft >= 0) return;
+ if (Ticker::TicksLeft >= 0) {
+ return;
+ }
auto am = a.get_allocator();
ASSERT_EQ(3, a.size()) << "u(il).size() fail";
int i = 1;
auto it = a.begin();
- for (; it != a.end(); ++it, i += 3)
+ for (; it != a.end(); ++it, i += 3) {
ASSERT_EQ(i, convertToInt(*it)) << "u(il) constructed incorrectly";
}
+}
//----------------------------
// insert-and-erase subsection
STL_TEST("23.2.3 Table 100.7", iteratorInsertionRV,
is_move_constructibleAndAssignable, a, p, t) {
// rvalue-references cannot have their address checked for aliased inserts
- if (a.data() <= addressof(t) && addressof(t) < a.data() + a.size()) return;
+ if (a.data() <= addressof(t) && addressof(t) < a.data() + a.size()) {
+ return;
+ }
DataState<Vector> dsa(a);
int idx = distance(a.begin(), p);
STL_TEST("23.2.3 Table 100.10", iteratorInsertIL,
is_arithmetic, a, p) {
// gcc fail
- if (Ticker::TicksLeft >= 0) return;
+ if (Ticker::TicksLeft >= 0) {
+ return;
+ }
// whitebox: ensure that insert(p, il) is implemented in terms of
// insert(p, il.begin(), il.end())
int i = 0;
auto it = a.begin();
for (; it != a.end(); ++it, ++i) {
- if (i == idx) i += n;
+ if (i == idx) {
+ i += n;
+ }
ASSERT_EQ(dsa[i], convertToInt(*it));
}
}
STL_TEST("23.2.3 Table 100.11", iteratorErase, is_move_assignable, a, p) {
- if (p == a.end()) return;
+ if (p == a.end()) {
+ return;
+ }
DataState<Vector> dsa(a);
int idx = distance(a.begin(), p);
STL_TEST("23.2.3 Table 100.12", iteratorEraseRange,
is_move_assignable, a, p, q) {
- if (p == a.end()) return;
+ if (p == a.end()) {
+ return;
+ }
DataState<Vector> dsa(a);
int idx = distance(a.begin(), p);
ASSERT_TRUE(am == a.get_allocator());
ASSERT_EQ(distance(i, j), a.size());
- for (auto it = a.begin(); it != a.end(); ++it, ++i)
+ for (auto it = a.begin(); it != a.end(); ++it, ++i) {
ASSERT_EQ(*i, convertToInt(*it));
}
+}
STL_TEST("23.2.3 Table 100.14", assignInputRange,
is_move_constructibleAndAssignable, a, i, j) {
ASSERT_TRUE(am == a.get_allocator());
ASSERT_EQ(distance(i, j), a.size());
- for (auto it = a.begin(); it != a.end(); ++it, ++i)
+ for (auto it = a.begin(); it != a.end(); ++it, ++i) {
ASSERT_EQ(*i, convertToInt(*it));
}
+}
STL_TEST("23.2.3 Table 100.15", assignIL,
is_arithmetic, a) {
// assign(il.begin(), il.end())
// gcc fail
- if (Ticker::TicksLeft >= 0) return;
+ if (Ticker::TicksLeft >= 0) {
+ return;
+ }
auto am = a.get_allocator();
int* i = ila;
ASSERT_EQ(3, a.size());
- for (auto it = a.begin(); it != a.end(); ++it, ++i)
+ for (auto it = a.begin(); it != a.end(); ++it, ++i) {
ASSERT_EQ(*i, convertToInt(*it));
}
+}
STL_TEST("23.2.3 Table 100.16", assignN,
is_copy_constructibleAndAssignable, a, n, t) {
ASSERT_TRUE(am == a.get_allocator());
ASSERT_EQ(n, a.size());
- for (auto it = a.begin(); it != a.end(); ++it)
+ for (auto it = a.begin(); it != a.end(); ++it) {
ASSERT_EQ(tval, convertToInt(*it));
}
+}
STL_TEST("23.2.3 Table 101.1", front, is_destructible, a) {
- if (a.empty()) return;
+ if (a.empty()) {
+ return;
+ }
ASSERT_TRUE(addressof(a.front()) == a.data());
}
STL_TEST("23.2.3 Table 101.2", back, is_destructible, a) {
- if (a.empty()) return;
+ if (a.empty()) {
+ return;
+ }
ASSERT_TRUE(addressof(a.back()) == a.data() + a.size() - 1);
}
ASSERT_TRUE(am == a.get_allocator());
- if (excess > 0) ASSERT_TRUE(a.data() == adata) << "unnecessary relocation";
+ if (excess > 0) {
+ ASSERT_TRUE(a.data() == adata) << "unnecessary relocation";
+ }
ASSERT_EQ(dsa.size() + 1, a.size());
size_t i = 0;
auto it = a.begin();
- for (; i < dsa.size(); ++i, ++it)
+ for (; i < dsa.size(); ++i, ++it) {
ASSERT_EQ(dsa[i], convertToInt(*it));
+ }
ASSERT_EQ(44, convertToInt(a.back()));
}
}
ASSERT_TRUE(am == a.get_allocator());
- if (excess > 0) ASSERT_TRUE(a.data() == adata) << "unnecessary relocation";
+ if (excess > 0) {
+ ASSERT_TRUE(a.data() == adata) << "unnecessary relocation";
+ }
ASSERT_EQ(dsa.size() + 1, a.size());
size_t i = 0;
auto it = a.begin();
- for (; i < dsa.size(); ++i, ++it)
+ for (; i < dsa.size(); ++i, ++it) {
ASSERT_EQ(dsa[i], convertToInt(*it));
+ }
ASSERT_EQ(tval, convertToInt(a.back()));
}
}
ASSERT_TRUE(am == a.get_allocator());
- if (excess > 0) ASSERT_TRUE(a.data() == adata) << "unnecessary relocation";
+ if (excess > 0) {
+ ASSERT_TRUE(a.data() == adata) << "unnecessary relocation";
+ }
ASSERT_EQ(dsa.size() + 1, a.size());
size_t i = 0;
auto it = a.begin();
- for (; i < dsa.size(); ++i, ++it)
+ for (; i < dsa.size(); ++i, ++it) {
ASSERT_EQ(dsa[i], convertToInt(*it));
+ }
ASSERT_EQ(tval, convertToInt(a.back()));
}
STL_TEST("23.2.3 Table 100.10", popBack, is_destructible, a) {
- if (a.empty()) return;
+ if (a.empty()) {
+ return;
+ }
DataState<Vector> dsa(a);
auto am = a.get_allocator();
ASSERT_EQ(dsa.size() - 1, a.size());
size_t i = 0;
auto it = a.begin();
- for (; it != a.end(); ++it, ++i)
+ for (; it != a.end(); ++it, ++i) {
ASSERT_EQ(dsa[i], convertToInt(*it));
}
+}
STL_TEST("23.2.3 Table 100.11", operatorBrace, is_destructible, a) {
const auto& ca = a;
- for (size_t i = 0; i < ca.size(); ++i)
+ for (size_t i = 0; i < ca.size(); ++i) {
ASSERT_TRUE(addressof(ca[i]) == ca.data()+i);
+ }
ASSERT_EQ(0, Counter::CountTotalOps);
STL_TEST("23.2.3 Table 100.12", at, is_destructible, a) {
const auto& ca = a;
- for (size_t i = 0; i < ca.size(); ++i)
+ for (size_t i = 0; i < ca.size(); ++i) {
ASSERT_TRUE(addressof(ca.at(i)) == ca.data()+i);
+ }
ASSERT_EQ(0, Counter::CountTotalOps);
STL_TEST("23.3.6.3", lengthError, is_move_constructible) {
auto mx = Vector().max_size();
auto big = mx+1;
- if (mx >= big) return; // max_size is the biggest size_type; overflowed
+ if (mx >= big) {
+ return; // max_size is the biggest size_type; overflowed
+ }
Vector u;
try {