Commit c2691bc6 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot 3

Don't use ?:

Summary:
Because it doesn't exist in the C++ standard.

This switches them to the explicitly expanded form, which is in the spec.
It also removes a few that were doing absolutely nothing. (MSVC still complained about the division by zero)

Reviewed By: yfeldblum

Differential Revision: D3479260

fbshipit-source-id: 5386e27057beeb4b228f5d6be4e1cf9941cf3176
parent bfe4b109
...@@ -345,8 +345,9 @@ class Adaptor { ...@@ -345,8 +345,9 @@ class Adaptor {
lastCount_(lastCount) { lastCount_(lastCount) {
} }
explicit Adaptor(size_t n, const value_type& value = value_type()) explicit Adaptor(size_t n, const value_type& value = value_type())
: c_(Node::nodeCount(n), fullNode(value)), : c_(Node::nodeCount(n), fullNode(value)) {
lastCount_(n % Node::kElementCount ?: Node::kElementCount) { const auto count = n % Node::kElementCount;
lastCount_ = count != 0 ? count : Node::kElementCount;
} }
Adaptor(const Adaptor&) = default; Adaptor(const Adaptor&) = default;
......
...@@ -125,7 +125,7 @@ struct BitVectorEncoder { ...@@ -125,7 +125,7 @@ struct BitVectorEncoder {
reinterpret_cast<folly::Unaligned<uint64_t>*>(block), inner); reinterpret_cast<folly::Unaligned<uint64_t>*>(block), inner);
if (skipQuantum != 0) { if (skipQuantum != 0) {
size_t nextSkipPointerSize = value / (skipQuantum ?: 1); size_t nextSkipPointerSize = value / skipQuantum;
while (skipPointersSize_ < nextSkipPointerSize) { while (skipPointersSize_ < nextSkipPointerSize) {
auto pos = skipPointersSize_++; auto pos = skipPointersSize_++;
folly::storeUnaligned<SkipValueType>( folly::storeUnaligned<SkipValueType>(
...@@ -134,8 +134,8 @@ struct BitVectorEncoder { ...@@ -134,8 +134,8 @@ struct BitVectorEncoder {
} }
if (forwardQuantum != 0) { if (forwardQuantum != 0) {
if (size_ != 0 && (size_ % (forwardQuantum ?: 1) == 0)) { if (size_ != 0 && (size_ % forwardQuantum == 0)) {
const auto pos = size_ / (forwardQuantum ?: 1) - 1; const auto pos = size_ / forwardQuantum - 1;
folly::storeUnaligned<SkipValueType>( folly::storeUnaligned<SkipValueType>(
forwardPointers_ + pos * sizeof(SkipValueType), value); forwardPointers_ + pos * sizeof(SkipValueType), value);
} }
...@@ -179,11 +179,11 @@ struct BitVectorEncoder<Value, SkipValue, kSkipQuantum, kForwardQuantum>:: ...@@ -179,11 +179,11 @@ struct BitVectorEncoder<Value, SkipValue, kSkipQuantum, kForwardQuantum>::
layout.bits = bitVectorSizeInBytes; layout.bits = bitVectorSizeInBytes;
if (skipQuantum != 0) { if (skipQuantum != 0) {
size_t numSkipPointers = upperBound / (skipQuantum ?: 1); size_t numSkipPointers = upperBound / skipQuantum;
layout.skipPointers = numSkipPointers * sizeof(SkipValueType); layout.skipPointers = numSkipPointers * sizeof(SkipValueType);
} }
if (forwardQuantum != 0) { if (forwardQuantum != 0) {
size_t numForwardPointers = size / (forwardQuantum ?: 1); size_t numForwardPointers = size / forwardQuantum;
layout.forwardPointers = numForwardPointers * sizeof(SkipValueType); layout.forwardPointers = numForwardPointers * sizeof(SkipValueType);
} }
...@@ -300,15 +300,12 @@ class BitVectorReader { ...@@ -300,15 +300,12 @@ class BitVectorReader {
// Use forward pointer. // Use forward pointer.
if (Encoder::forwardQuantum > 0 && n > Encoder::forwardQuantum) { if (Encoder::forwardQuantum > 0 && n > Encoder::forwardQuantum) {
// Workaround to avoid 'division by zero' compile-time error. const size_t steps = position_ / Encoder::forwardQuantum;
constexpr size_t q = Encoder::forwardQuantum ?: 1;
const size_t steps = position_ / q;
const size_t dest = folly::loadUnaligned<SkipValueType>( const size_t dest = folly::loadUnaligned<SkipValueType>(
forwardPointers_ + (steps - 1) * sizeof(SkipValueType)); forwardPointers_ + (steps - 1) * sizeof(SkipValueType));
reposition(dest); reposition(dest);
n = position_ + 1 - steps * q; n = position_ + 1 - steps * Encoder::forwardQuantum;
// Correct inner_ will be set at the end. // Correct inner_ will be set at the end.
} }
......
...@@ -255,9 +255,7 @@ struct EliasFanoEncoderV2<Value, ...@@ -255,9 +255,7 @@ struct EliasFanoEncoderV2<Value,
// more serialization-friendly way (upperSizeBits doesn't need // more serialization-friendly way (upperSizeBits doesn't need
// to be known by this function, unlike upper). // to be known by this function, unlike upper).
// '?: 1' is a workaround for false 'division by zero' size_t numSkipPointers = (8 * upper - size) / skipQuantum;
// compile-time error.
size_t numSkipPointers = (8 * upper - size) / (skipQuantum ?: 1);
layout.skipPointers = numSkipPointers * sizeof(SkipValueType); layout.skipPointers = numSkipPointers * sizeof(SkipValueType);
} }
...@@ -265,7 +263,7 @@ struct EliasFanoEncoderV2<Value, ...@@ -265,7 +263,7 @@ struct EliasFanoEncoderV2<Value,
// Store (1-indexed) position of every forwardQuantum-th // Store (1-indexed) position of every forwardQuantum-th
// 1-bit in upper bits sequence. // 1-bit in upper bits sequence.
/* static */ if (forwardQuantum != 0) { /* static */ if (forwardQuantum != 0) {
size_t numForwardPointers = size / (forwardQuantum ?: 1); size_t numForwardPointers = size / forwardQuantum;
layout.forwardPointers = numForwardPointers * sizeof(SkipValueType); layout.forwardPointers = numForwardPointers * sizeof(SkipValueType);
} }
...@@ -369,16 +367,13 @@ class UpperBitsReader { ...@@ -369,16 +367,13 @@ class UpperBitsReader {
// Use forward pointer. // Use forward pointer.
if (Encoder::forwardQuantum > 0 && n > Encoder::forwardQuantum) { if (Encoder::forwardQuantum > 0 && n > Encoder::forwardQuantum) {
// Workaround to avoid 'division by zero' compile-time error. const size_t steps = position_ / Encoder::forwardQuantum;
constexpr size_t q = Encoder::forwardQuantum ?: 1;
const size_t steps = position_ / q;
const size_t dest = const size_t dest =
folly::loadUnaligned<SkipValueType>( folly::loadUnaligned<SkipValueType>(
forwardPointers_ + (steps - 1) * sizeof(SkipValueType)); forwardPointers_ + (steps - 1) * sizeof(SkipValueType));
reposition(dest + steps * q); reposition(dest + steps * Encoder::forwardQuantum);
n = position_ + 1 - steps * q; // n is > 0. n = position_ + 1 - steps * Encoder::forwardQuantum; // n is > 0.
// Correct inner_ will be set at the end. // Correct inner_ will be set at the end.
} }
...@@ -405,15 +400,12 @@ class UpperBitsReader { ...@@ -405,15 +400,12 @@ class UpperBitsReader {
// Use skip pointer. // Use skip pointer.
if (Encoder::skipQuantum > 0 && v >= value_ + Encoder::skipQuantum) { if (Encoder::skipQuantum > 0 && v >= value_ + Encoder::skipQuantum) {
// Workaround to avoid 'division by zero' compile-time error. const size_t steps = v / Encoder::skipQuantum;
constexpr size_t q = Encoder::skipQuantum ?: 1;
const size_t steps = v / q;
const size_t dest = const size_t dest =
folly::loadUnaligned<SkipValueType>( folly::loadUnaligned<SkipValueType>(
skipPointers_ + (steps - 1) * sizeof(SkipValueType)); skipPointers_ + (steps - 1) * sizeof(SkipValueType));
reposition(dest + q * steps); reposition(dest + Encoder::skipQuantum * steps);
position_ = dest - 1; position_ = dest - 1;
// Correct inner_ and value_ will be set during the next() // Correct inner_ and value_ will be set during the next()
......
...@@ -292,8 +292,9 @@ class Parallel : public Operator<Parallel<Ops>> { ...@@ -292,8 +292,9 @@ class Parallel : public Operator<Parallel<Ops>> {
Generator(Source source, Ops ops, size_t threads) Generator(Source source, Ops ops, size_t threads)
: source_(std::move(source)), : source_(std::move(source)),
ops_(std::move(ops)), ops_(std::move(ops)),
threads_(threads threads_(
?: std::max<size_t>(1, sysconf(_SC_NPROCESSORS_CONF))) {} threads ? threads
: std::max<size_t>(1, sysconf(_SC_NPROCESSORS_CONF))) {}
template <class Handler> template <class Handler>
bool apply(Handler&& handler) const { bool apply(Handler&& handler) const {
......
...@@ -148,7 +148,7 @@ class PMap : public Operator<PMap<Predicate>> { ...@@ -148,7 +148,7 @@ class PMap : public Operator<PMap<Predicate>> {
Generator(Source source, const Predicate& pred, size_t nThreads) Generator(Source source, const Predicate& pred, size_t nThreads)
: source_(std::move(source)), : source_(std::move(source)),
pred_(pred), pred_(pred),
nThreads_(nThreads ?: sysconf(_SC_NPROCESSORS_ONLN)) { nThreads_(nThreads ? nThreads : sysconf(_SC_NPROCESSORS_ONLN)) {
} }
template<class Body> template<class Body>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment