Commit fafeb979 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Write /* static */ if as if /* constexpr */

Summary: [Folly] Write `/* static */ if` as `if /* constexpr */`. Once the time comes to jump to C++17, all that remains is to remove the comments.

Reviewed By: aary

Differential Revision: D9627826

fbshipit-source-id: 56078e727a3a4420851f1c441783b80da55a8e6c
parent e9842c1e
......@@ -197,7 +197,7 @@ class ConcurrentSkipList {
//===================================================================
~ConcurrentSkipList() {
/* static */ if (NodeType::template DestroyIsNoOp<NodeAlloc>::value) {
if /* constexpr */ (NodeType::template DestroyIsNoOp<NodeAlloc>::value) {
// Avoid traversing the list if using arena allocator.
return;
}
......
......@@ -1224,14 +1224,14 @@ typename std::enable_if<
std::is_integral<Tgt>::value,
Expected<Tgt, ConversionCode>>::type
convertTo(const Src& value) noexcept {
/* static */ if (
if /* constexpr */ (
folly::_t<std::make_unsigned<Tgt>>(std::numeric_limits<Tgt>::max()) <
folly::_t<std::make_unsigned<Src>>(std::numeric_limits<Src>::max())) {
if (greater_than<Tgt, std::numeric_limits<Tgt>::max()>(value)) {
return makeUnexpected(ConversionCode::ARITH_POSITIVE_OVERFLOW);
}
}
/* static */ if (
if /* constexpr */ (
std::is_signed<Src>::value &&
(!std::is_signed<Tgt>::value || sizeof(Src) > sizeof(Tgt))) {
if (less_than<Tgt, std::numeric_limits<Tgt>::min()>(value)) {
......@@ -1252,7 +1252,7 @@ typename std::enable_if<
!std::is_same<Tgt, Src>::value,
Expected<Tgt, ConversionCode>>::type
convertTo(const Src& value) noexcept {
/* static */ if (
if /* constexpr */ (
std::numeric_limits<Tgt>::max() < std::numeric_limits<Src>::max()) {
if (value > std::numeric_limits<Tgt>::max()) {
return makeUnexpected(ConversionCode::ARITH_POSITIVE_OVERFLOW);
......
......@@ -141,7 +141,7 @@ template <class Pod, class T>
inline void podFill(Pod* b, Pod* e, T c) {
FBSTRING_ASSERT(b && e && b <= e);
constexpr auto kUseMemset = sizeof(T) == 1;
/* static */ if (kUseMemset) {
if /* constexpr */ (kUseMemset) {
memset(b, c, size_t(e - b));
} else {
auto const ee = b + ((e - b) & ~7u);
......@@ -477,7 +477,7 @@ template <class Char> class fbstring_core {
size_t size() const {
size_t ret = ml_.size_;
/* static */ if (kIsLittleEndian) {
if /* constexpr */ (kIsLittleEndian) {
// We can save a couple instructions, because the category is
// small iff the last char, as unsigned, is <= maxSmallSize.
typedef typename std::make_unsigned<Char>::type UChar;
......
......@@ -171,14 +171,14 @@ struct EliasFanoEncoderV2 {
writeBits56(lower_, size_ * numLowerBits, numLowerBits, lowerBits);
}
/* static */ if (skipQuantum != 0) {
if /* constexpr */ (skipQuantum != 0) {
while ((skipPointersSize_ + 1) * skipQuantum <= upperBits) {
// Store the number of preceding 1-bits.
skipPointers_[skipPointersSize_++] = SkipValue(size_);
}
}
/* static */ if (forwardQuantum != 0) {
if /* constexpr */ (forwardQuantum != 0) {
if ((size_ + 1) % forwardQuantum == 0) {
const auto k = size_ / forwardQuantum;
// Store the number of preceding 0-bits.
......@@ -264,7 +264,7 @@ struct EliasFanoEncoderV2<Value,
// *** Skip pointers.
// Store (1-indexed) position of every skipQuantum-th
// 0-bit in upper bits sequence.
/* static */ if (skipQuantum != 0) {
if /* constexpr */ (skipQuantum != 0) {
// 8 * upper is used here instead of upperSizeBits, as that is
// more serialization-friendly way (upperSizeBits doesn't need
// to be known by this function, unlike upper).
......@@ -276,7 +276,7 @@ struct EliasFanoEncoderV2<Value,
// *** Forward pointers.
// Store (1-indexed) position of every forwardQuantum-th
// 1-bit in upper bits sequence.
/* static */ if (forwardQuantum != 0) {
if /* constexpr */ (forwardQuantum != 0) {
size_t numForwardPointers = size / forwardQuantum;
layout.forwardPointers = numForwardPointers * sizeof(SkipValueType);
}
......
......@@ -94,7 +94,7 @@ size_t hash_combine_generic(
return seed;
}
size_t remainder = hash_combine_generic(h, ts...);
/* static */ if (sizeof(size_t) == sizeof(uint32_t)) {
if /* constexpr */ (sizeof(size_t) == sizeof(uint32_t)) {
return twang_32from64((uint64_t(seed) << 32) | remainder);
} else {
return static_cast<size_t>(hash_128_to_64(seed, remainder));
......
......@@ -73,7 +73,7 @@ struct PerfTest {
}
void consumer() {
/*static*/ if (Pop) {
if /* constexpr */ (Pop) {
while (!done_) {
if (queue_.frontPtr()) {
queue_.popFront();
......
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