#endif
}
-int getGlobalBenchmarkBaselineIndex() {
+size_t getGlobalBenchmarkBaselineIndex() {
const char *global = FB_STRINGIZE_X2(FB_FOLLY_GLOBAL_BENCHMARK_BASELINE);
auto it = std::find_if(
benchmarks().begin(),
}
);
CHECK(it != benchmarks().end());
- return it - benchmarks().begin();
+ return size_t(std::distance(benchmarks().begin(), it));
}
#undef FB_STRINGIZE_X2
// PLEASE KEEP QUIET. MEASUREMENTS IN PROGRESS.
- unsigned int baselineIndex = getGlobalBenchmarkBaselineIndex();
+ size_t baselineIndex = getGlobalBenchmarkBaselineIndex();
auto const globalBaseline =
runBenchmarkGetNSPerIteration(get<2>(benchmarks()[baselineIndex]), 0);
BenchmarkSuspender(const BenchmarkSuspender &) = delete;
BenchmarkSuspender(BenchmarkSuspender && rhs) noexcept {
start = rhs.start;
- rhs.start.tv_nsec = rhs.start.tv_sec = 0;
+ rhs.start = {0, 0};
}
BenchmarkSuspender& operator=(const BenchmarkSuspender &) = delete;
tally();
}
start = rhs.start;
- rhs.start.tv_nsec = rhs.start.tv_sec = 0;
+ rhs.start = {0, 0};
return *this;
}
void dismiss() {
assert(start.tv_nsec > 0 || start.tv_sec > 0);
tally();
- start.tv_nsec = start.tv_sec = 0;
+ start = {0, 0};
}
void rehire() {
other.bitOffset_ - bitOffset_;
}
- unsigned int bitOffset_;
+ size_t bitOffset_;
};
/**
// Process 8 bytes at a time until we have fewer than 8 bytes left.
while (offset + sizeof(uint64_t) <= nbytes) {
const uint64_t* src = (const uint64_t*)(data + offset);
- sum = _mm_crc32_u64(sum, *src);
+ sum = uint32_t(_mm_crc32_u64(sum, *src));
offset += sizeof(uint64_t);
}
// The code in this file that uses tolower() really only cares about
// 7-bit ASCII characters, so we can take a nice shortcut here.
inline char tolower_ascii(char in) {
- return IsAscii::value ? in | 0x20 : std::tolower(in);
+ return IsAscii::value ? in | 0x20 : char(std::tolower(in));
}
inline bool bool_str_cmp(const char** b, size_t len, const char* value) {
return makeUnexpected(ConversionCode::EMPTY_INPUT_STRING);
}
src->advance(length);
- return result;
+ return Tgt(result);
}
auto* e = src->end();
src->assign(b, e);
- return result;
+ return Tgt(result);
}
template Expected<float, ConversionCode> str_to_floating<float>(
if (sum >= OOR) {
goto outOfRange;
}
- result = 1000 * result + sum;
+ result = UT(1000 * result + sum);
break;
}
case 2: {
if (sum >= OOR) {
goto outOfRange;
}
- result = 100 * result + sum;
+ result = UT(100 * result + sum);
break;
}
case 1: {
if (sum >= OOR) {
goto outOfRange;
}
- result = 10 * result + sum;
+ result = UT(10 * result + sum);
break;
}
default:
// Keep these together so a peephole optimization "sees" them and
// computes them in one shot.
auto const q = v / 10;
- auto const r = static_cast<uint32_t>(v % 10);
+ auto const r = static_cast<char>(v % 10);
buffer[pos--] = '0' + r;
v = q;
}
// Last digit is trivial to handle
- buffer[pos] = static_cast<uint32_t>(v) + '0';
+ buffer[pos] = static_cast<char>(v) + '0';
return result;
}
// small_[maxSmallSize].
FBSTRING_ASSERT(s <= maxSmallSize);
constexpr auto shift = kIsLittleEndian ? 0 : 2;
- small_[maxSmallSize] = (maxSmallSize - s) << shift;
+ small_[maxSmallSize] = char((maxSmallSize - s) << shift);
small_[s] = '\0';
FBSTRING_ASSERT(category() == Category::isSmall && size() == s);
}
using namespace fileutil_detail;
int openNoInt(const char* name, int flags, mode_t mode) {
- return wrapNoInt(open, name, flags, mode);
+ return int(wrapNoInt(open, name, flags, mode));
}
int closeNoInt(int fd) {
}
int fsyncNoInt(int fd) {
- return wrapNoInt(fsync, fd);
+ return int(wrapNoInt(fsync, fd));
}
int dupNoInt(int fd) {
- return wrapNoInt(dup, fd);
+ return int(wrapNoInt(dup, fd));
}
int dup2NoInt(int oldfd, int newfd) {
- return wrapNoInt(dup2, oldfd, newfd);
+ return int(wrapNoInt(dup2, oldfd, newfd));
}
int fdatasyncNoInt(int fd) {
#if defined(__APPLE__)
- return wrapNoInt(fcntl, fd, F_FULLFSYNC);
+ return int(wrapNoInt(fcntl, fd, F_FULLFSYNC));
#elif defined(__FreeBSD__) || defined(_MSC_VER)
- return wrapNoInt(fsync, fd);
+ return int(wrapNoInt(fsync, fd));
#else
- return wrapNoInt(fdatasync, fd);
+ return int(wrapNoInt(fdatasync, fd));
#endif
}
int ftruncateNoInt(int fd, off_t len) {
- return wrapNoInt(ftruncate, fd, len);
+ return int(wrapNoInt(ftruncate, fd, len));
}
int truncateNoInt(const char* path, off_t len) {
- return wrapNoInt(truncate, path, len);
+ return int(wrapNoInt(truncate, path, len));
}
int flockNoInt(int fd, int operation) {
- return wrapNoInt(flock, fd, operation);
+ return int(wrapNoInt(flock, fd, operation));
}
int shutdownNoInt(int fd, int how) {
- return wrapNoInt(portability::sockets::shutdown, fd, how);
+ return int(wrapNoInt(portability::sockets::shutdown, fd, how));
}
ssize_t readNoInt(int fd, void* buf, size_t count) {
namespace detail {
void insertThousandsGroupingUnsafe(char* start_buffer, char** end_buffer) {
- uint32_t remaining_digits = *end_buffer - start_buffer;
+ uint32_t remaining_digits = uint32_t(*end_buffer - start_buffer);
uint32_t separator_size = (remaining_digits - 1) / 3;
uint32_t result_size = remaining_digits + separator_size;
*end_buffer = *end_buffer + separator_size;
private:
static uint8_t key(uint32_t x) {
// __builtin_clz is undefined for the x==0 case
- return 3 - (__builtin_clz(x|1) / 8);
+ return uint8_t(3 - (__builtin_clz(x | 1) / 8));
}
static size_t b0key(size_t x) { return x & 3; }
static size_t b1key(size_t x) { return (x >> 2) & 3; }
static uint8_t key(uint64_t x) {
// __builtin_clzll is undefined for the x==0 case
- return 7 - (__builtin_clzll(x|1) / 8);
+ return uint8_t(7 - (__builtin_clzll(x | 1) / 8));
}
static uint8_t b0key(uint16_t x) { return x & 7; }
static constexpr uint32_t maxIndexForCapacity(uint32_t capacity) {
// index of uint32_t(-1) == UINT32_MAX is reserved for isAllocated tracking
- return std::min(uint64_t(capacity) + (NumLocalLists - 1) * LocalListLimit,
- uint64_t(uint32_t(-1) - 1));
+ return uint32_t(std::min(
+ uint64_t(capacity) + (NumLocalLists - 1) * LocalListLimit,
+ uint64_t(uint32_t(-1) - 1)));
}
static constexpr uint32_t capacityForMaxIndex(uint32_t maxIndex) {
auto slot = reinterpret_cast<const Slot*>(
reinterpret_cast<const char*>(elem) - offsetof(Slot, elem));
- auto rv = slot - slots_;
+ auto rv = uint32_t(slot - slots_);
// this assert also tests that rv is in range
assert(elem == &(*this)[rv]);
/// corresponding SingleElementQueue
uint32_t turn(uint64_t ticket, size_t cap) noexcept {
assert(cap != 0);
- return ticket / cap;
+ return uint32_t(ticket / cap);
}
/// Tries to obtain a push ticket for which SingleElementQueue::enqueue
}
if (pageSize == 0) {
- pageSize = sysconf(_SC_PAGESIZE);
+ pageSize = off_t(sysconf(_SC_PAGESIZE));
}
CHECK_GT(pageSize, 0);
CHECK_GE(offset, 0);
// Round down the start of the mapped region
- size_t skipStart = offset % pageSize;
+ off_t skipStart = offset % pageSize;
offset -= skipStart;
mapLength_ = length;
return chunkSize;
}
- chunkSize = FLAGS_mlock_chunk_size;
+ chunkSize = off_t(FLAGS_mlock_chunk_size);
off_t r = chunkSize % pageSize;
if (r) {
chunkSize += (pageSize - r);
// chunks breaks the locking into intervals and lets other threads do memory
// operations of their own.
- size_t chunkSize = memOpChunkSize(bufSize, pageSize);
+ size_t chunkSize = memOpChunkSize(off_t(bufSize), pageSize);
char* addr = static_cast<char*>(mem);
amountSucceeded = 0;
MemoryMapping destMap(
File(dest, O_RDWR | O_CREAT | O_TRUNC, mode),
0,
- srcMap.range().size(),
+ off_t(srcMap.range().size()),
MemoryMapping::writable());
alignedForwardMemcpy(destMap.writableRange().data(),
if (r) {
DCHECK_LT(size_, kCapacity);
dense_[size_] = i;
- sparse_[i] = size_;
+ sparse_[i] = uint8_t(size_);
size_++;
}
return r;
remainder = (length - ((const uint8_t *)end-(const uint8_t *)message));
memcpy(buf, end, remainder);
memset(((uint8_t *)buf)+remainder, 0, sc_blockSize-remainder);
- ((uint8_t *)buf)[sc_blockSize-1] = remainder;
+ ((uint8_t*)buf)[sc_blockSize - 1] = uint8_t(remainder);
Mix(buf, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
// do some final mixing
remainder = (length - ((const uint8_t *)end-(const uint8_t *)message));
memcpy(buf, end, remainder);
memset(((uint8_t *)buf)+remainder, 0, sc_blockSize-remainder);
- ((uint8_t *)buf)[sc_blockSize-1] = remainder;
+ ((uint8_t*)buf)[sc_blockSize - 1] = uint8_t(remainder);
// do some final mixing
End(buf, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
bestPrefixId = j;
}
} else if (prettyString->startsWith(suffixes[j].suffix)) {
- int suffixLen = strlen(suffixes[j].suffix);
+ int suffixLen = int(strlen(suffixes[j].suffix));
//We are looking for a longest suffix matching prefix of the string
//after numeric value. We need this in case suffixes have common prefix.
if (suffixLen > longestPrefixLen) {
namespace {
-fbstring submatch(const boost::cmatch& m, size_t idx) {
+fbstring submatch(const boost::cmatch& m, int idx) {
auto& sub = m[idx];
return fbstring(sub.first, sub.second);
}
*p++ = 0x80 | (val & 0x7f);
val >>= 7;
}
- *p++ = val;
+ *p++ = uint8_t(val);
return p - buf;
}
}
#endif
- long numCpus = sysconf(_SC_NPROCESSORS_CONF);
+ size_t numCpus = sysconf(_SC_NPROCESSORS_CONF);
if (numCpus <= 0) {
// This shouldn't happen, but if it does we should try to keep
// going. We are probably not going to be able to parse /sys on
// a sub-optimal ordering, but it won't crash
auto& lhsEquiv = equivClassesByCpu[lhs];
auto& rhsEquiv = equivClassesByCpu[rhs];
- for (int i = std::min(lhsEquiv.size(), rhsEquiv.size()) - 1;
+ for (int i = int(std::min(lhsEquiv.size(), rhsEquiv.size())) - 1;
i >= 0;
--i) {
if (lhsEquiv[i] != rhsEquiv[i]) {
struct SequentialThreadId {
/// Returns the thread id assigned to the current thread
- static size_t get() {
+ static unsigned get() {
auto rv = currentId;
if (UNLIKELY(rv == 0)) {
rv = currentId = ++prevId;
}
private:
- static Atom<size_t> prevId;
+ static Atom<unsigned> prevId;
- static FOLLY_TLS size_t currentId;
+ static FOLLY_TLS unsigned currentId;
};
template <template <typename> class Atom>
-Atom<size_t> SequentialThreadId<Atom>::prevId(0);
+Atom<unsigned> SequentialThreadId<Atom>::prevId(0);
template <template <typename> class Atom>
-FOLLY_TLS size_t SequentialThreadId<Atom>::currentId(0);
+FOLLY_TLS unsigned SequentialThreadId<Atom>::currentId(0);
// Suppress this instantiation in other translation units. It is
// instantiated in CacheLocality.cpp
#endif
struct HashingThreadId {
- static size_t get() {
+ static unsigned get() {
pthread_t pid = pthread_self();
uint64_t id = 0;
memcpy(&id, &pid, std::min(sizeof(pid), sizeof(id)));
assert(index < n);
// as index goes from 0..n, post-transform value goes from
// 0..numStripes
- widthAndCpuToStripe[width][cpu] = (index * numStripes) / n;
+ widthAndCpuToStripe[width][cpu] =
+ CompactStripe((index * numStripes) / n);
assert(widthAndCpuToStripe[width][cpu] < numStripes);
}
for (size_t cpu = n; cpu < kMaxCpus; ++cpu) {
// multiplying the duration by a floating point doesn't work, grr..
auto extraFrac =
timeoutVariationFrac / std::numeric_limits<uint64_t>::max() * h;
- uint64_t tics = idleTimeout.count() * (1 + extraFrac);
+ auto tics = uint64_t(idleTimeout.count() * (1 + extraFrac));
idleTimeout = typename Clock::duration(tics);
}
// do an unaligned load for first block of haystack
auto arr1 = _mm_loadu_si128(
reinterpret_cast<const __m128i*>(haystack.data()));
- auto index = _mm_cmpestri(arr2, needles.size(),
- arr1, haystack.size(), 0);
+ auto index =
+ _mm_cmpestri(arr2, int(needles.size()), arr1, int(haystack.size()), 0);
if (index < 16) {
return index;
}
for (; i < haystack.size(); i+= 16) {
arr1 =
_mm_load_si128(reinterpret_cast<const __m128i*>(haystack.data() + i));
- index = _mm_cmpestri(arr2, needles.size(), arr1, haystack.size() - i, 0);
+ index = _mm_cmpestri(
+ arr2, int(needles.size()), arr1, int(haystack.size() - i), 0);
if (index < 16) {
return i + index;
}
// This load is safe because needles.size() >= 16
auto arr2 = _mm_loadu_si128(
reinterpret_cast<const __m128i*>(needles.data()));
- size_t b = _mm_cmpestri(
- arr2, 16, arr1, haystack.size() - blockStartIdx, 0);
+ size_t b =
+ _mm_cmpestri(arr2, 16, arr1, int(haystack.size() - blockStartIdx), 0);
size_t j = nextAlignedIndex(needles.data());
for (; j < needles.size(); j += 16) {
reinterpret_cast<const __m128i*>(needles.data() + j));
auto index = _mm_cmpestri(
- arr2, needles.size() - j,
- arr1, haystack.size() - blockStartIdx, 0);
+ arr2,
+ int(needles.size() - j),
+ arr1,
+ int(haystack.size() - blockStartIdx),
+ 0);
b = std::min<size_t>(index, b);
}
ReturnType>::type
avgHelper(ValueType sum, uint64_t count) {
if (count == 0) { return ReturnType(0); }
- const double sumf = sum;
- const double countf = count;
+ const double sumf = double(sum);
+ const double countf = double(count);
return static_cast<ReturnType>(sumf / countf);
}
/// Returns the least-most significant byte of the current uncompleted
/// turn. The full 32 bit turn cannot be recovered.
uint8_t uncompletedTurnLSB() const noexcept {
- return state_.load(std::memory_order_acquire) >> kTurnShift;
+ return uint8_t(state_.load(std::memory_order_acquire) >> kTurnShift);
}
private:
struct UniformDistributionFunctor {
std::default_random_engine generator;
- std::uniform_int_distribution<> dist;
+ std::uniform_int_distribution<milliseconds::rep> dist;
UniformDistributionFunctor(milliseconds minInterval, milliseconds maxInterval)
: generator(Random::rand32()),
errors.emplace_back(*se);
}
}
- const int success = validators_.size() - errors.size();
+ const auto success = validators_.size() - errors.size();
if (success == 0) {
return makeError("at least one valid schema", value);
} else if (success > 1 && type_ == Type::EXACTLY_ONE) {
.count() +
1;
// If clock is not monotonic
- delay_ms = std::max<decltype(delay_ms)>(delay_ms, 0L);
- eventBase_->tryRunAfterDelay(func, delay_ms);
+ delay_ms = std::max<decltype(delay_ms)>(delay_ms, 0);
+ eventBase_->tryRunAfterDelay(func, uint32_t(delay_ms));
}
}
} // folly::fibers
bool equal(const Iterator& other) const { return range_ == other.range_; }
void increment() {
size_t skip = recordio_helpers::headerSize() + recordAndPos_.first.size();
- recordAndPos_.second += skip;
+ recordAndPos_.second += off_t(skip);
range_.advance(skip);
advanceToValid();
}
DCHECK_EQ(buf->computeChainDataLength(), totalLength);
// We're going to write. Reserve space for ourselves.
- off_t pos = filePos_.fetch_add(totalLength);
+ off_t pos = filePos_.fetch_add(off_t(totalLength));
#if FOLLY_HAVE_PWRITEV
auto iov = buf->getIov();
skipped -= headerSize();
range_.advance(skipped);
recordAndPos_.first = record;
- recordAndPos_.second += skipped;
+ recordAndPos_.second += off_t(skipped);
}
}
memset(header, 0, sizeof(Header));
header->magic = detail::Header::kMagic;
header->fileId = fileId;
- header->dataLength = lengthAndHash.first;
+ header->dataLength = uint32_t(lengthAndHash.first);
header->dataHash = lengthAndHash.second;
header->headerHash = headerHash(*header);
namespace folly {
-ShutdownSocketSet::ShutdownSocketSet(size_t maxFd)
+ShutdownSocketSet::ShutdownSocketSet(int maxFd)
: maxFd_(maxFd),
data_(static_cast<std::atomic<uint8_t>*>(
folly::checkedCalloc(maxFd, sizeof(std::atomic<uint8_t>)))),
void ShutdownSocketSet::add(int fd) {
// Silently ignore any fds >= maxFd_, very unlikely
DCHECK_GE(fd, 0);
- if (size_t(fd) >= maxFd_) {
+ if (fd >= maxFd_) {
return;
}
void ShutdownSocketSet::remove(int fd) {
DCHECK_GE(fd, 0);
- if (size_t(fd) >= maxFd_) {
+ if (fd >= maxFd_) {
return;
}
int ShutdownSocketSet::close(int fd) {
DCHECK_GE(fd, 0);
- if (size_t(fd) >= maxFd_) {
+ if (fd >= maxFd_) {
return folly::closeNoInt(fd);
}
void ShutdownSocketSet::shutdown(int fd, bool abortive) {
DCHECK_GE(fd, 0);
- if (fd >= 0 && size_t(fd) >= maxFd_) {
+ if (fd >= maxFd_) {
doShutdown(fd, abortive);
return;
}
}
void ShutdownSocketSet::shutdownAll(bool abortive) {
- for (size_t i = 0; i < maxFd_; ++i) {
+ for (int i = 0; i < maxFd_; ++i) {
auto& sref = data_[i];
if (sref.load(std::memory_order_acquire) == IN_USE) {
shutdown(i, abortive);
* applications, even if you increased the number of file descriptors
* on your system.
*/
- explicit ShutdownSocketSet(size_t maxFd = 1 << 18);
+ explicit ShutdownSocketSet(int maxFd = 1 << 18);
/**
* Add an already open socket to the list of sockets managed by
}
};
- const size_t maxFd_;
+ const int maxFd_;
std::unique_ptr<std::atomic<uint8_t>[], Free> data_;
folly::File nullFile_;
};
std::string decodeUnicodeEscape(Input& in) {
auto hexVal = [&] (int c) -> uint16_t {
- return c >= '0' && c <= '9' ? c - '0' :
+ return uint16_t(
+ c >= '0' && c <= '9' ? c - '0' :
c >= 'a' && c <= 'f' ? c - 'a' + 10 :
c >= 'A' && c <= 'F' ? c - 'A' + 10 :
- (in.error("invalid hex digit"), 0);
+ (in.error("invalid hex digit"), 0));
};
auto readHex = [&]() -> uint16_t {
StringPiece input,
std::string& out,
const serialization_opts& opts) {
- auto hexDigit = [] (int c) -> char {
+ auto hexDigit = [] (uint8_t c) -> char {
return c < 10 ? c + '0' : c - 10 + 'a';
};
// with value > 127, so size > 1 byte
char32_t v = decodeUtf8(p, e, opts.skip_invalid_utf8);
out.append("\\u");
- out.push_back(hexDigit(v >> 12));
+ out.push_back(hexDigit(uint8_t(v >> 12)));
out.push_back(hexDigit((v >> 8) & 0x0f));
out.push_back(hexDigit((v >> 4) & 0x0f));
out.push_back(hexDigit(v & 0x0f));