From: Christopher Dykes Date: Thu, 21 Jul 2016 23:56:32 +0000 (-0700) Subject: Don't use ?: X-Git-Tag: 2016.07.26~18 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=c2691bc6bb023aa8082e26fa81137584ae7925a8;p=folly.git 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 --- diff --git a/folly/Padded.h b/folly/Padded.h index d474b850..aa2ddd36 100644 --- a/folly/Padded.h +++ b/folly/Padded.h @@ -345,8 +345,9 @@ class Adaptor { lastCount_(lastCount) { } explicit Adaptor(size_t n, const value_type& value = value_type()) - : c_(Node::nodeCount(n), fullNode(value)), - lastCount_(n % Node::kElementCount ?: Node::kElementCount) { + : c_(Node::nodeCount(n), fullNode(value)) { + const auto count = n % Node::kElementCount; + lastCount_ = count != 0 ? count : Node::kElementCount; } Adaptor(const Adaptor&) = default; diff --git a/folly/experimental/BitVectorCoding.h b/folly/experimental/BitVectorCoding.h index 836f137c..d51b7b96 100644 --- a/folly/experimental/BitVectorCoding.h +++ b/folly/experimental/BitVectorCoding.h @@ -125,7 +125,7 @@ struct BitVectorEncoder { reinterpret_cast*>(block), inner); if (skipQuantum != 0) { - size_t nextSkipPointerSize = value / (skipQuantum ?: 1); + size_t nextSkipPointerSize = value / skipQuantum; while (skipPointersSize_ < nextSkipPointerSize) { auto pos = skipPointersSize_++; folly::storeUnaligned( @@ -134,8 +134,8 @@ struct BitVectorEncoder { } if (forwardQuantum != 0) { - if (size_ != 0 && (size_ % (forwardQuantum ?: 1) == 0)) { - const auto pos = size_ / (forwardQuantum ?: 1) - 1; + if (size_ != 0 && (size_ % forwardQuantum == 0)) { + const auto pos = size_ / forwardQuantum - 1; folly::storeUnaligned( forwardPointers_ + pos * sizeof(SkipValueType), value); } @@ -179,11 +179,11 @@ struct BitVectorEncoder:: layout.bits = bitVectorSizeInBytes; if (skipQuantum != 0) { - size_t numSkipPointers = upperBound / (skipQuantum ?: 1); + size_t numSkipPointers = upperBound / skipQuantum; layout.skipPointers = numSkipPointers * sizeof(SkipValueType); } if (forwardQuantum != 0) { - size_t numForwardPointers = size / (forwardQuantum ?: 1); + size_t numForwardPointers = size / forwardQuantum; layout.forwardPointers = numForwardPointers * sizeof(SkipValueType); } @@ -300,15 +300,12 @@ class BitVectorReader { // Use forward pointer. if (Encoder::forwardQuantum > 0 && n > Encoder::forwardQuantum) { - // Workaround to avoid 'division by zero' compile-time error. - constexpr size_t q = Encoder::forwardQuantum ?: 1; - - const size_t steps = position_ / q; + const size_t steps = position_ / Encoder::forwardQuantum; const size_t dest = folly::loadUnaligned( forwardPointers_ + (steps - 1) * sizeof(SkipValueType)); reposition(dest); - n = position_ + 1 - steps * q; + n = position_ + 1 - steps * Encoder::forwardQuantum; // Correct inner_ will be set at the end. } diff --git a/folly/experimental/EliasFanoCoding.h b/folly/experimental/EliasFanoCoding.h index 1acb3eca..8508f329 100644 --- a/folly/experimental/EliasFanoCoding.h +++ b/folly/experimental/EliasFanoCoding.h @@ -255,9 +255,7 @@ struct EliasFanoEncoderV2 0 && n > Encoder::forwardQuantum) { - // Workaround to avoid 'division by zero' compile-time error. - constexpr size_t q = Encoder::forwardQuantum ?: 1; - - const size_t steps = position_ / q; + const size_t steps = position_ / Encoder::forwardQuantum; const size_t dest = folly::loadUnaligned( forwardPointers_ + (steps - 1) * sizeof(SkipValueType)); - reposition(dest + steps * q); - n = position_ + 1 - steps * q; // n is > 0. + reposition(dest + steps * Encoder::forwardQuantum); + n = position_ + 1 - steps * Encoder::forwardQuantum; // n is > 0. // Correct inner_ will be set at the end. } @@ -405,15 +400,12 @@ class UpperBitsReader { // Use skip pointer. if (Encoder::skipQuantum > 0 && v >= value_ + Encoder::skipQuantum) { - // Workaround to avoid 'division by zero' compile-time error. - constexpr size_t q = Encoder::skipQuantum ?: 1; - - const size_t steps = v / q; + const size_t steps = v / Encoder::skipQuantum; const size_t dest = folly::loadUnaligned( skipPointers_ + (steps - 1) * sizeof(SkipValueType)); - reposition(dest + q * steps); + reposition(dest + Encoder::skipQuantum * steps); position_ = dest - 1; // Correct inner_ and value_ will be set during the next() diff --git a/folly/gen/Parallel-inl.h b/folly/gen/Parallel-inl.h index 7ce349b7..5a5e347a 100644 --- a/folly/gen/Parallel-inl.h +++ b/folly/gen/Parallel-inl.h @@ -292,8 +292,9 @@ class Parallel : public Operator> { Generator(Source source, Ops ops, size_t threads) : source_(std::move(source)), ops_(std::move(ops)), - threads_(threads - ?: std::max(1, sysconf(_SC_NPROCESSORS_CONF))) {} + threads_( + threads ? threads + : std::max(1, sysconf(_SC_NPROCESSORS_CONF))) {} template bool apply(Handler&& handler) const { diff --git a/folly/gen/ParallelMap-inl.h b/folly/gen/ParallelMap-inl.h index eb2899cd..4048b3ae 100644 --- a/folly/gen/ParallelMap-inl.h +++ b/folly/gen/ParallelMap-inl.h @@ -148,7 +148,7 @@ class PMap : public Operator> { Generator(Source source, const Predicate& pred, size_t nThreads) : source_(std::move(source)), pred_(pred), - nThreads_(nThreads ?: sysconf(_SC_NPROCESSORS_ONLN)) { + nThreads_(nThreads ? nThreads : sysconf(_SC_NPROCESSORS_ONLN)) { } template