Commit 7ffe7766 authored by Daniel Sommermann's avatar Daniel Sommermann Committed by Pavlo Kushnir

Fix -Wsign-compare

Summary: Folly should be able to compile with strict flags.

Test Plan: unit tests, review

Reviewed By: meyering@fb.com

Subscribers: meyering, trunkagent, doug, fugalh, njormrod, folly-diffs@

FB internal diff: D1627280

Signature: t1:1627280:1414792755:004f5a737ece1e93bcf4331718a98afc57e4f80c
parent c16a74ff
......@@ -75,10 +75,11 @@ inline uint64_t timespecDiff(timespec end, timespec start) {
assert(end.tv_nsec >= start.tv_nsec);
return end.tv_nsec - start.tv_nsec;
}
assert(end.tv_sec > start.tv_sec &&
(uint64_t)(end.tv_sec - start.tv_sec) <
assert(end.tv_sec > start.tv_sec);
auto diff = uint64_t(end.tv_sec - start.tv_sec);
assert(diff <
std::numeric_limits<uint64_t>::max() / 1000000000UL);
return (end.tv_sec - start.tv_sec) * 1000000000UL
return diff * 1000000000UL
+ end.tv_nsec - start.tv_nsec;
}
......
......@@ -148,7 +148,7 @@ static inline uint16_t unpack(uint8_t lobyte, uint8_t hibyte) {
static inline void unpackInto(const unsigned char* src,
uint16_t* dest,
size_t count) {
for (int i = 0, hi = 1, lo = 0; i < count; i++) {
for (size_t i = 0, hi = 1, lo = 0; i < count; i++) {
dest[i] = unpack(src[hi], src[lo]);
hi += 2;
lo += 2;
......
......@@ -33,7 +33,8 @@ namespace {
void readRandomDevice(void* data, size_t size) {
// Keep it open for the duration of the program
static File randomDevice("/dev/urandom");
PCHECK(readFull(randomDevice.fd(), data, size) == size);
auto bytesRead = readFull(randomDevice.fd(), data, size);
PCHECK(bytesRead >= 0 && size_t(bytesRead) == size);
}
class BufferedRandomDevice {
......
......@@ -52,7 +52,7 @@ inline void stringPrintfImpl(std::string& output, const char* format,
throw std::runtime_error(
to<std::string>("Invalid format string; snprintf returned negative "
"with format string: ", format));
} else if (bytes_used < remaining) {
} else if (size_t(bytes_used) < remaining) {
// There was enough room, just shrink and return.
output.resize(write_point + bytes_used);
} else {
......@@ -63,7 +63,7 @@ inline void stringPrintfImpl(std::string& output, const char* format,
bytes_used = vsnprintf(&output[write_point], remaining, format,
args_copy);
va_end(args_copy);
if (bytes_used + 1 != remaining) {
if (size_t(bytes_used) + 1 != remaining) {
throw std::runtime_error(
to<std::string>("vsnprint retry did not manage to work "
"with format string: ", format));
......
......@@ -118,7 +118,7 @@ namespace {
// Copy pointers to the given strings in a format suitable for posix_spawn
std::unique_ptr<const char*[]> cloneStrings(const std::vector<std::string>& s) {
std::unique_ptr<const char*[]> d(new const char*[s.size() + 1]);
for (int i = 0; i < s.size(); i++) {
for (size_t i = 0; i < s.size(); i++) {
d[i] = s[i].c_str();
}
d[s.size()] = nullptr;
......@@ -738,7 +738,7 @@ void Subprocess::communicate(FdCallback readCallback,
} while (r == -1 && errno == EINTR);
checkUnixError(r, "poll");
for (int i = 0; i < pipes_.size(); ++i) {
for (size_t i = 0; i < pipes_.size(); ++i) {
auto& p = pipes_[i];
DCHECK_EQ(fds[i].fd, p.parentFd);
short events = fds[i].revents;
......
......@@ -94,7 +94,8 @@ inline uint64_t decodeVarint(ByteRange& data) {
const int8_t* p = begin;
uint64_t val = 0;
if (LIKELY(end - begin >= kMaxVarintLength64)) { // fast path
// end is always greater than or equal to begin, so this subtraction is safe
if (LIKELY(size_t(end - begin) >= kMaxVarintLength64)) { // fast path
int64_t b;
do {
b = *p++; val = (b & 0x7f) ; if (b >= 0) break;
......
......@@ -80,10 +80,10 @@ const CacheLocality& CacheLocality::system<std::atomic>() {
/// Returns the first decimal number in the string, or throws an exception
/// if the string does not start with a number terminated by ',', '-',
/// '\n', or eos.
static ssize_t parseLeadingNumber(const std::string& line) {
static size_t parseLeadingNumber(const std::string& line) {
auto raw = line.c_str();
char *end;
unsigned val = strtoul(raw, &end, 10);
unsigned long val = strtoul(raw, &end, 10);
if (end == raw || (*end != ',' && *end != '-' && *end != '\n')) {
throw std::runtime_error(to<std::string>(
"error parsing list '", line, "'").c_str());
......@@ -165,7 +165,7 @@ CacheLocality CacheLocality::readFromSysfsTree(
// to each other than entries that are far away. For striping we want
// the inverse map, since we are starting with the cpu
std::vector<size_t> indexes(cpus.size());
for (int i = 0; i < cpus.size(); ++i) {
for (size_t i = 0; i < cpus.size(); ++i) {
indexes[cpus[i]] = i;
}
......
......@@ -54,7 +54,7 @@ std::ostream& operator<<(std::ostream& out, const ExceptionInfo& info) {
<< (info.frames.size() == 1 ? " frame" : " frames")
<< ")\n";
try {
ssize_t frameCount = info.frames.size();
size_t frameCount = info.frames.size();
// Skip our own internal frames
static constexpr size_t skip = 3;
......
......@@ -136,7 +136,7 @@ void testReadsSerially(const std::vector<TestSpec>& specs,
::close(fd);
};
for (int i = 0; i < specs.size(); i++) {
for (size_t i = 0; i < specs.size(); i++) {
auto buf = allocateAligned(specs[i].size);
op.pread(fd, buf.get(), specs[i].size, specs[i].start);
aioReader.submit(&op);
......@@ -171,14 +171,14 @@ void testReadsParallel(const std::vector<TestSpec>& specs,
if (multithreaded) {
threads.reserve(specs.size());
}
for (int i = 0; i < specs.size(); i++) {
for (size_t i = 0; i < specs.size(); i++) {
bufs.push_back(allocateAligned(specs[i].size));
}
auto submit = [&] (int i) {
auto submit = [&] (size_t i) {
ops[i].pread(fd, bufs[i].get(), specs[i].size, specs[i].start);
aioReader.submit(&ops[i]);
};
for (int i = 0; i < specs.size(); i++) {
for (size_t i = 0; i < specs.size(); i++) {
if (multithreaded) {
threads.emplace_back([&submit, i] { submit(i); });
} else {
......@@ -198,7 +198,7 @@ void testReadsParallel(const std::vector<TestSpec>& specs,
EXPECT_NE(nrRead, 0);
remaining -= nrRead;
for (int i = 0; i < nrRead; i++) {
for (size_t i = 0; i < nrRead; i++) {
int id = completed[i] - ops.get();
EXPECT_GE(id, 0);
EXPECT_LT(id, specs.size());
......@@ -212,7 +212,7 @@ void testReadsParallel(const std::vector<TestSpec>& specs,
EXPECT_EQ(specs.size(), aioReader.totalSubmits());
EXPECT_EQ(aioReader.pending(), 0);
for (int i = 0; i < pending.size(); i++) {
for (size_t i = 0; i < pending.size(); i++) {
EXPECT_FALSE(pending[i]);
}
}
......@@ -230,7 +230,7 @@ void testReadsQueued(const std::vector<TestSpec>& specs,
SCOPE_EXIT {
::close(fd);
};
for (int i = 0; i < specs.size(); i++) {
for (size_t i = 0; i < specs.size(); i++) {
bufs.push_back(allocateAligned(specs[i].size));
ops[i].pread(fd, bufs[i].get(), specs[i].size, specs[i].start);
aioQueue.submit(&ops[i]);
......@@ -251,7 +251,7 @@ void testReadsQueued(const std::vector<TestSpec>& specs,
EXPECT_NE(nrRead, 0);
remaining -= nrRead;
for (int i = 0; i < nrRead; i++) {
for (size_t i = 0; i < nrRead; i++) {
int id = completed[i] - ops.get();
EXPECT_GE(id, 0);
EXPECT_LT(id, specs.size());
......@@ -265,7 +265,7 @@ void testReadsQueued(const std::vector<TestSpec>& specs,
EXPECT_EQ(specs.size(), aioReader.totalSubmits());
EXPECT_EQ(aioReader.pending(), 0);
EXPECT_EQ(aioQueue.queued(), 0);
for (int i = 0; i < pending.size(); i++) {
for (size_t i = 0; i < pending.size(); i++) {
EXPECT_FALSE(pending[i]);
}
}
......
......@@ -234,7 +234,7 @@ void dumpStackTrace(bool symbolize) {
} else {
print("(safe mode, symbolizer not available)\n");
AddressFormatter formatter;
for (ssize_t i = 0; i < addresses.frameCount; ++i) {
for (size_t i = 0; i < addresses.frameCount; ++i) {
print(formatter.format(addresses.addresses[i]));
print("\n");
}
......
......@@ -66,7 +66,7 @@ ssize_t getStackTraceSafe(uintptr_t* addresses, size_t maxAddresses) {
return -1;
}
++addresses;
ssize_t count = 1;
size_t count = 1;
for (; count != maxAddresses; ++count, ++addresses) {
int r = unw_step(&cursor);
if (r < 0) {
......
......@@ -367,13 +367,13 @@ struct BenchmarkSingleton {
};
BENCHMARK(NormalSingleton, n) {
for (int i = 0; i < n; ++i) {
for (size_t i = 0; i < n; ++i) {
doNotOptimizeAway(getNormalSingleton());
}
}
BENCHMARK_RELATIVE(MeyersSingleton, n) {
for (int i = 0; i < n; ++i) {
for (size_t i = 0; i < n; ++i) {
doNotOptimizeAway(getMeyersSingleton());
}
}
......@@ -384,7 +384,7 @@ BENCHMARK_RELATIVE(FollySingleton, n) {
nullptr, nullptr, &benchmark_vault);
benchmark_vault.registrationComplete();
for (int i = 0; i < n; ++i) {
for (size_t i = 0; i < n; ++i) {
doNotOptimizeAway(Singleton<BenchmarkSingleton>::get(&benchmark_vault));
}
}
......
......@@ -74,7 +74,7 @@ void CPUThreadPoolExecutor::threadRun(std::shared_ptr<Thread> thread) {
void CPUThreadPoolExecutor::stopThreads(size_t n) {
CHECK(stoppedThreads_.size() == 0);
threadsToStop_ = n;
for (int i = 0; i < n; i++) {
for (size_t i = 0; i < n; i++) {
taskQueue_->add(CPUTask());
}
}
......
......@@ -132,7 +132,7 @@ void IOThreadPoolExecutor::threadRun(ThreadPtr thread) {
// threadListLock_ is writelocked
void IOThreadPoolExecutor::stopThreads(size_t n) {
for (int i = 0; i < n; i++) {
for (size_t i = 0; i < n; i++) {
const auto ioThread = std::static_pointer_cast<IOThread>(
threadList_.get()[i]);
ioThread->shouldRun = false;
......
......@@ -85,7 +85,7 @@ void ThreadPoolExecutor::setNumThreads(size_t n) {
// threadListLock_ is writelocked
void ThreadPoolExecutor::addThreads(size_t n) {
std::vector<ThreadPtr> newThreads;
for (int i = 0; i < n; i++) {
for (size_t i = 0; i < n; i++) {
newThreads.push_back(makeThread());
}
for (auto& thread : newThreads) {
......@@ -106,7 +106,7 @@ void ThreadPoolExecutor::removeThreads(size_t n, bool isJoin) {
CHECK(stoppedThreads_.size() == 0);
isJoin_ = isJoin;
stopThreads(n);
for (int i = 0; i < n; i++) {
for (size_t i = 0; i < n; i++) {
auto thread = stoppedThreads_.take();
thread->handle.join();
threadList_.remove(thread);
......
......@@ -37,8 +37,8 @@ BENCHMARK(ByLine_Pipes, iters) {
PCHECK(::write(wfd, &x, 1) == 1); // signal startup
FILE* f = fdopen(wfd, "w");
PCHECK(f);
for (int i = 1; i <= iters; ++i) {
fprintf(f, "%d\n", i);
for (size_t i = 1; i <= iters; ++i) {
fprintf(f, "%zu\n", i);
}
fclose(f);
});
......
......@@ -64,7 +64,7 @@ BENCHMARK_RELATIVE(FibSumThreads, n) {
| sum;
folly::doNotOptimizeAway(result);
};
for (int i = 0; i < kNumThreads; i++) {
for (size_t i = 0; i < kNumThreads; i++) {
workers.push_back(std::thread(fn));
}
for (auto& w : workers) { w.join(); }
......
......@@ -275,7 +275,7 @@ void checkResplitMaxLength(vector<string> ins,
splitter.flush();
EXPECT_EQ(outs.size(), pieces.size());
for (int i = 0; i < outs.size(); ++i) {
for (size_t i = 0; i < outs.size(); ++i) {
EXPECT_EQ(outs[i], pieces[i]);
}
......
......@@ -295,7 +295,7 @@ std::unique_ptr<IOBuf> LZ4Codec::doUncompress(
p.second,
actualUncompressedLength);
if (n != actualUncompressedLength) {
if (n < 0 || uint64_t(n) != actualUncompressedLength) {
throw std::runtime_error(to<std::string>(
"LZ4 decompression returned invalid value ", n));
}
......
......@@ -47,7 +47,7 @@ void Appender::vprintf(const char* fmt, va_list ap) {
}
// vsnprintf() returns the number of characters that would be printed,
// not including the terminating nul.
if (ret < length()) {
if (size_t(ret) < length()) {
// All of the data was successfully written.
append(ret);
return;
......@@ -61,7 +61,7 @@ void Appender::vprintf(const char* fmt, va_list ap) {
if (ret < 0) {
throw std::runtime_error("error formatting printf() data");
}
if (ret >= length()) {
if (size_t(ret) >= length()) {
// This shouldn't ever happen.
throw std::runtime_error("unexpectedly out of buffer space on second "
"vsnprintf() attmept");
......
......@@ -78,7 +78,8 @@ RecordIOReader::Iterator::Iterator(ByteRange range, uint32_t fileId, off_t pos)
: range_(range),
fileId_(fileId),
recordAndPos_(ByteRange(), 0) {
if (pos >= range_.size()) {
if (size_t(pos) >= range_.size()) {
// Note that this branch can execute if pos is negative as well.
recordAndPos_.second = off_t(-1);
range_.clear();
} else {
......
......@@ -39,7 +39,7 @@ ShutdownSocketSet::ShutdownSocketSet(size_t maxFd)
void ShutdownSocketSet::add(int fd) {
// Silently ignore any fds >= maxFd_, very unlikely
DCHECK_GE(fd, 0);
if (fd >= maxFd_) {
if (size_t(fd) >= maxFd_) {
return;
}
......@@ -53,7 +53,7 @@ void ShutdownSocketSet::add(int fd) {
void ShutdownSocketSet::remove(int fd) {
DCHECK_GE(fd, 0);
if (fd >= maxFd_) {
if (size_t(fd) >= maxFd_) {
return;
}
......@@ -81,7 +81,7 @@ retry:
int ShutdownSocketSet::close(int fd) {
DCHECK_GE(fd, 0);
if (fd >= maxFd_) {
if (size_t(fd) >= maxFd_) {
return folly::closeNoInt(fd);
}
......@@ -113,7 +113,7 @@ retry:
void ShutdownSocketSet::shutdown(int fd, bool abortive) {
DCHECK_GE(fd, 0);
if (fd >= maxFd_) {
if (fd >= 0 && size_t(fd) >= maxFd_) {
doShutdown(fd, abortive);
return;
}
......
......@@ -1284,7 +1284,7 @@ void AsyncSocket::handleRead() noexcept {
// completely filled the available buffer.
// Note that readCallback_ may have been uninstalled or changed inside
// readDataAvailable().
if (bytesRead < buflen) {
if (size_t(bytesRead) < buflen) {
return;
}
} else if (bytesRead == READ_BLOCKING) {
......
......@@ -351,14 +351,14 @@ TEST(IOBufQueue, PopFirst) {
const size_t numStrings=sizeof(strings)/sizeof(*strings);
size_t chainLength = 0;
for(ssize_t i=0; i<numStrings; ++i) {
for(size_t i = 0; i < numStrings; ++i) {
queue.append(stringToIOBuf(strings[i], strlen(strings[i])));
checkConsistency(queue);
chainLength += strlen(strings[i]);
}
unique_ptr<IOBuf> first;
for(ssize_t i=0; i<numStrings; ++i) {
for(size_t i = 0; i < numStrings; ++i) {
checkConsistency(queue);
EXPECT_EQ(chainLength, queue.front()->computeChainDataLength());
EXPECT_EQ(chainLength, queue.chainLength());
......
......@@ -94,14 +94,14 @@ TEST(RecordIOTest, SmallRecords) {
TemporaryFile file;
{
RecordIOWriter writer(File(file.fd()));
for (int i = 0; i < kSize; ++i) { // record of size 0 should be ignored
for (size_t i = 0; i < kSize; ++i) { // record of size 0 should be ignored
writer.write(IOBuf::wrapBuffer(tmp, i));
}
}
{
RecordIOReader reader(File(file.fd()));
auto it = reader.begin();
for (int i = 1; i < kSize; ++i) {
for (size_t i = 1; i < kSize; ++i) {
ASSERT_FALSE(it == reader.end());
EXPECT_EQ(StringPiece(tmp, i), sp((it++)->first));
}
......
......@@ -90,7 +90,6 @@ TEST(Ahm, BasicNoncopyable) {
}
typedef int32_t KeyT;
typedef int64_t KeyTBig;
typedef int32_t ValueT;
typedef AtomicHashMap<KeyT,ValueT> AHMapT;
......@@ -109,7 +108,7 @@ static int genVal(int key) {
TEST(Ahm, grow) {
VLOG(1) << "Overhead: " << sizeof(AHArrayT) << " (array) " <<
sizeof(AHMapT) + sizeof(AHArrayT) << " (map/set) Bytes.";
int numEntries = 10000;
uint64_t numEntries = 10000;
float sizeFactor = 0.46;
std::unique_ptr<AHMapT> m(new AHMapT(int(numEntries * sizeFactor), config));
......@@ -138,7 +137,7 @@ TEST(Ahm, grow) {
EXPECT_GT(m->numSubMaps(), 1); // make sure we grew
success = true;
EXPECT_EQ(m->size(), numEntries);
for (int i = 0; i < numEntries; i++) {
for (size_t i = 0; i < numEntries; i++) {
success &= (m->find(i)->second == genVal(i));
}
EXPECT_TRUE(success);
......@@ -147,10 +146,12 @@ TEST(Ahm, grow) {
success = true;
KeyT key(0);
AHMapT::const_iterator retIt;
for (uint64_t i = 0; i < numEntries; i++) {
for (int32_t i = 0; i < int32_t(numEntries); i++) {
retIt = m->find(i);
retIt = m->findAt(retIt.getIndex());
success &= (retIt->second == genVal(i));
// We use a uint32_t index so that this comparison is between two
// variables of the same type.
success &= (retIt->first == i);
}
EXPECT_TRUE(success);
......@@ -175,7 +176,7 @@ TEST(Ahm, iterator) {
std::unique_ptr<AHMapT> m(new AHMapT(int(numEntries * sizeFactor), config));
// load map - make sure we succeed and the index is accurate
for (uint64_t i = 0; i < numEntries; i++) {
for (int i = 0; i < numEntries; i++) {
m->insert(RecordT(i, genVal(i)));
}
......@@ -296,7 +297,7 @@ TEST(Ahm, map_exception_safety) {
}
TEST(Ahm, basicErase) {
int numEntries = 3000;
size_t numEntries = 3000;
std::unique_ptr<AHMapT> s(new AHMapT(numEntries, config));
// Iterate filling up the map and deleting all keys a few times
......@@ -304,7 +305,7 @@ TEST(Ahm, basicErase) {
for (int iterations = 0; iterations < 4; ++iterations) {
// Testing insertion of keys
bool success = true;
for (uint64_t i = 0; i < numEntries; ++i) {
for (size_t i = 0; i < numEntries; ++i) {
success &= !(s->count(i));
auto ret = s->insert(RecordT(i, i));
success &= s->count(i);
......@@ -316,7 +317,7 @@ TEST(Ahm, basicErase) {
// Delete every key in the map and verify that the key is gone and the the
// size is correct.
success = true;
for (uint64_t i = 0; i < numEntries; ++i) {
for (size_t i = 0; i < numEntries; ++i) {
success &= s->erase(i);
success &= (s->size() == numEntries - 1 - i);
success &= !(s->count(i));
......@@ -374,7 +375,7 @@ void runThreads(void *(*thread)(void*), int numThreads, void **statuses) {
susp.dismiss();
runThreadsCreatedAllThreads.store(true);
for (int i = 0; i < threadIds.size(); ++i) {
for (size_t i = 0; i < threadIds.size(); ++i) {
pthread_join(threadIds[i], statuses == nullptr ? nullptr : &statuses[i]);
}
}
......@@ -502,7 +503,7 @@ TEST(Ahm, race_insert_iterate_thread_test) {
threadIds.push_back(tid);
}
}
for (int i = 0; i < threadIds.size(); ++i) {
for (size_t i = 0; i < threadIds.size(); ++i) {
pthread_join(threadIds[i], nullptr);
}
VLOG(1) << "Ended up with " << globalAHM->numSubMaps() << " submaps";
......@@ -578,7 +579,7 @@ TEST(Ahm, thread_erase_insert_race) {
threadIds.push_back(tid);
}
}
for (int i = 0; i < threadIds.size(); i++) {
for (size_t i = 0; i < threadIds.size(); i++) {
pthread_join(threadIds[i], nullptr);
}
......@@ -651,7 +652,7 @@ void loadGlobalAhm() {
BENCHMARK(st_aha_find, iters) {
CHECK_LE(iters, FLAGS_numBMElements);
for (int i = 0; i < iters; i++) {
for (size_t i = 0; i < iters; i++) {
KeyT key = randomizeKey(i);
folly::doNotOptimizeAway(globalAHA->find(key)->second);
}
......@@ -659,7 +660,7 @@ BENCHMARK(st_aha_find, iters) {
BENCHMARK(st_ahm_find, iters) {
CHECK_LE(iters, FLAGS_numBMElements);
for (int i = 0; i < iters; i++) {
for (size_t i = 0; i < iters; i++) {
KeyT key = randomizeKey(i);
folly::doNotOptimizeAway(globalAHM->find(key)->second);
}
......@@ -683,7 +684,7 @@ BENCHMARK(mt_ahm_miss, iters) {
BENCHMARK(st_ahm_miss, iters) {
CHECK_LE(iters, FLAGS_numBMElements);
for (int i = 0; i < iters; i++) {
for (size_t i = 0; i < iters; i++) {
KeyT key = randomizeKey(i + iters * 100);
folly::doNotOptimizeAway(globalAHM->find(key) == globalAHM->end());
}
......@@ -738,7 +739,7 @@ BENCHMARK(mt_ahm_find, iters) {
KeyT k;
BENCHMARK(st_baseline_modulus_and_random, iters) {
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
k = randomizeKey(i) % iters;
}
}
......@@ -758,7 +759,7 @@ BENCHMARK(st_ahm_insert, iters) {
std::unique_ptr<AHMapT> ahm(new AHMapT(int(iters * LF), config));
susp.dismiss();
for (int i = 0; i < iters; i++) {
for (size_t i = 0; i < iters; i++) {
KeyT key = randomizeKey(i);
ahm->insert(key, genVal(key));
}
......
......@@ -76,12 +76,12 @@ BENCHMARK(posix_sem_pingpong, iters) {
sem_init(a, 0, 0);
sem_init(b, 0, 0);
auto thr = std::thread([=]{
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
sem_wait(a);
sem_post(b);
}
});
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
sem_post(a);
sem_wait(b);
}
......
......@@ -302,7 +302,7 @@ BENCHMARK(Accessor, iters) {
auto sl = skiplist.get();
susp.dismiss();
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
SkipListAccessor accessor(sl);
}
}
......@@ -318,7 +318,7 @@ BENCHMARK(accessorBasicRefcounting, iters) {
l.init();
susp.dismiss();
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
value->fetch_add(1, std::memory_order_relaxed);
if (dirty->load(std::memory_order_acquire) != 0) {
folly::MSLGuard g(l);
......@@ -407,23 +407,23 @@ class ConcurrentAccessData {
sets_[idx].erase(val);
}
void runSkipList(int id, int iters) {
void runSkipList(int id, size_t iters) {
int sum = 0;
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
sum += accessSkipList(id, i);
}
// VLOG(20) << sum;
}
void runSet(int id, int iters) {
void runSet(size_t id, size_t iters) {
int sum = 0;
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
sum += accessSet(id, i);
}
// VLOG(20) << sum;
}
bool accessSkipList(int64_t id, int t) {
bool accessSkipList(int64_t id, size_t t) {
if (t > readValues_.size()) {
t = t % readValues_.size();
}
......@@ -441,7 +441,7 @@ class ConcurrentAccessData {
}
}
bool accessSet(int64_t id, int t) {
bool accessSet(int64_t id, size_t t) {
if (t > readValues_.size()) {
t = t % readValues_.size();
}
......
......@@ -273,7 +273,7 @@ void testConcurrentAdd(int numThreads) {
<< ": could only create " << threads.size() << " threads out of "
<< numThreads;
}
for (int i = 0; i < threads.size(); ++i) {
for (size_t i = 0; i < threads.size(); ++i) {
threads[i].join();
}
......
......@@ -986,7 +986,7 @@ static float fValue = 1.2355;
static double dValue = 345345345.435;
BENCHMARK(preallocateTestNoFloat, n) {
for (int i=0; i < n; ++i) {
for (size_t i = 0; i < n; ++i) {
auto val1 = to<std::string>(bigInt, someString, stdString, otherString);
auto val3 = to<std::string>(reallyShort, smallInt);
auto val2 = to<std::string>(bigInt, stdString);
......@@ -996,7 +996,7 @@ BENCHMARK(preallocateTestNoFloat, n) {
}
BENCHMARK(preallocateTestFloat, n) {
for (int i=0; i < n; ++i) {
for (size_t i = 0; i < n; ++i) {
auto val1 = to<std::string>(stdString, ',', fValue, dValue);
auto val2 = to<std::string>(stdString, ',', dValue);
}
......
......@@ -58,7 +58,7 @@ DeterministicSchedule::~DeterministicSchedule() {
std::function<int(int)>
DeterministicSchedule::uniform(long seed) {
auto rand = std::make_shared<std::ranlux48>(seed);
return [rand](int numActive) {
return [rand](size_t numActive) {
auto dist = std::uniform_int_distribution<int>(0, numActive - 1);
return dist(*rand);
};
......@@ -73,7 +73,7 @@ struct UniformSubset {
{
}
int operator()(int numActive) {
size_t operator()(size_t numActive) {
adjustPermSize(numActive);
if (stepsLeft_-- == 0) {
stepsLeft_ = stepsBetweenSelect_ - 1;
......@@ -84,17 +84,17 @@ struct UniformSubset {
private:
std::function<int(int)> uniform_;
const int subsetSize_;
const size_t subsetSize_;
const int stepsBetweenSelect_;
int stepsLeft_;
// only the first subsetSize_ is properly randomized
std::vector<int> perm_;
void adjustPermSize(int numActive) {
void adjustPermSize(size_t numActive) {
if (perm_.size() > numActive) {
perm_.erase(std::remove_if(perm_.begin(), perm_.end(),
[=](int x){ return x >= numActive; }), perm_.end());
[=](size_t x){ return x >= numActive; }), perm_.end());
} else {
while (perm_.size() < numActive) {
perm_.push_back(perm_.size());
......@@ -104,7 +104,7 @@ struct UniformSubset {
}
void shufflePrefix() {
for (int i = 0; i < std::min(int(perm_.size() - 1), subsetSize_); ++i) {
for (size_t i = 0; i < std::min(perm_.size() - 1, subsetSize_); ++i) {
int j = uniform_(perm_.size() - i) + i;
std::swap(perm_[i], perm_[j]);
}
......@@ -114,7 +114,7 @@ struct UniformSubset {
std::function<int(int)>
DeterministicSchedule::uniformSubset(long seed, int n, int m) {
auto gen = std::make_shared<UniformSubset>(seed, n, m);
return [=](int numActive) { return (*gen)(numActive); };
return [=](size_t numActive) { return (*gen)(numActive); };
}
void
......
......@@ -34,7 +34,7 @@ DEFINE_int32(num_threads, 32, "Number of threads to run concurrency "
*/
BENCHMARK(exception_ptr_create_and_test, iters) {
std::runtime_error e("payload");
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
auto ep = std::make_exception_ptr(e);
assert(ep);
}
......@@ -42,7 +42,7 @@ BENCHMARK(exception_ptr_create_and_test, iters) {
BENCHMARK_RELATIVE(exception_wrapper_create_and_test, iters) {
std::runtime_error e("payload");
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
assert(ew);
}
......@@ -58,7 +58,7 @@ BENCHMARK(exception_ptr_create_and_test_concurrent, iters) {
threads.emplace_back([&go, iters] {
while (!go) { }
std::runtime_error e("payload");
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
auto ep = std::make_exception_ptr(e);
assert(ep);
}
......@@ -79,7 +79,7 @@ BENCHMARK_RELATIVE(exception_wrapper_create_and_test_concurrent, iters) {
threads.emplace_back([&go, iters] {
while (!go) { }
std::runtime_error e("payload");
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
assert(ew);
}
......@@ -101,7 +101,7 @@ BENCHMARK_DRAW_LINE()
*/
BENCHMARK(exception_ptr_create_and_throw, iters) {
std::runtime_error e("payload");
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
auto ep = std::make_exception_ptr(e);
try {
std::rethrow_exception(ep);
......@@ -113,7 +113,7 @@ BENCHMARK(exception_ptr_create_and_throw, iters) {
BENCHMARK_RELATIVE(exception_wrapper_create_and_throw, iters) {
std::runtime_error e("payload");
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
try {
ew.throwException();
......@@ -125,7 +125,7 @@ BENCHMARK_RELATIVE(exception_wrapper_create_and_throw, iters) {
BENCHMARK_RELATIVE(exception_wrapper_create_and_cast, iters) {
std::runtime_error e("payload");
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
assert(ew.is_compatible_with<std::runtime_error>());
}
......@@ -142,7 +142,7 @@ BENCHMARK(exception_ptr_create_and_throw_concurrent, iters) {
threads.emplace_back([&go, iters] {
while (!go) { }
std::runtime_error e("payload");
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
auto ep = std::make_exception_ptr(e);
try {
std::rethrow_exception(ep);
......@@ -167,7 +167,7 @@ BENCHMARK_RELATIVE(exception_wrapper_create_and_throw_concurrent, iters) {
threads.emplace_back([&go, iters] {
while (!go) { }
std::runtime_error e("payload");
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
try {
ew.throwException();
......@@ -192,7 +192,7 @@ BENCHMARK_RELATIVE(exception_wrapper_create_and_cast_concurrent, iters) {
threads.emplace_back([&go, iters] {
while (!go) { }
std::runtime_error e("payload");
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
assert(ew.is_compatible_with<std::runtime_error>());
}
......
......@@ -21,12 +21,12 @@
* override-include-guard
*/
void BENCHFUN(initRNG)(int iters, int) {
void BENCHFUN(initRNG)(size_t iters, size_t) {
srand(seed);
}
BENCHMARK_PARAM(BENCHFUN(initRNG), 0);
void BENCHFUN(defaultCtor)(int iters, int) {
void BENCHFUN(defaultCtor)(size_t iters, size_t) {
FOR_EACH_RANGE (i, 0, iters) {
STRING s[4096];
doNotOptimizeAway(&s);
......@@ -34,7 +34,7 @@ void BENCHFUN(defaultCtor)(int iters, int) {
}
BENCHMARK_PARAM(BENCHFUN(defaultCtor), 0);
void BENCHFUN(copyCtor)(int iters, int arg) {
void BENCHFUN(copyCtor)(size_t iters, size_t arg) {
STRING s;
BENCHMARK_SUSPEND {
randomString(&s, arg);
......@@ -46,7 +46,7 @@ void BENCHFUN(copyCtor)(int iters, int arg) {
}
BENCHMARK_PARAM(BENCHFUN(copyCtor), 32768);
void BENCHFUN(ctorFromArray)(int iters, int arg) {
void BENCHFUN(ctorFromArray)(size_t iters, size_t arg) {
STRING s;
BENCHMARK_SUSPEND {
randomString(&s, arg);
......@@ -61,7 +61,7 @@ void BENCHFUN(ctorFromArray)(int iters, int arg) {
}
BENCHMARK_PARAM(BENCHFUN(ctorFromArray), 32768);
void BENCHFUN(ctorFromTwoPointers)(int iters, int arg) {
void BENCHFUN(ctorFromTwoPointers)(size_t iters, size_t arg) {
static STRING s;
BENCHMARK_SUSPEND {
if (s.size() < arg) s.resize(arg);
......@@ -77,7 +77,7 @@ BENCHMARK_PARAM(BENCHFUN(ctorFromTwoPointers), 15);
BENCHMARK_PARAM(BENCHFUN(ctorFromTwoPointers), 23);
BENCHMARK_PARAM(BENCHFUN(ctorFromTwoPointers), 24);
void BENCHFUN(ctorFromChar)(int iters, int arg) {
void BENCHFUN(ctorFromChar)(size_t iters, size_t arg) {
FOR_EACH_RANGE (i, 0, iters) {
STRING s1('a', arg);
doNotOptimizeAway(&s1);
......@@ -85,7 +85,7 @@ void BENCHFUN(ctorFromChar)(int iters, int arg) {
}
BENCHMARK_PARAM(BENCHFUN(ctorFromChar), 1048576);
void BENCHFUN(assignmentOp)(int iters, int arg) {
void BENCHFUN(assignmentOp)(size_t iters, size_t arg) {
STRING s;
BENCHMARK_SUSPEND {
randomString(&s, arg);
......@@ -101,7 +101,7 @@ void BENCHFUN(assignmentOp)(int iters, int arg) {
}
BENCHMARK_PARAM(BENCHFUN(assignmentOp), 256);
void BENCHFUN(assignmentFill)(int iters, int) {
void BENCHFUN(assignmentFill)(size_t iters, size_t) {
STRING s;
FOR_EACH_RANGE (i, 0, iters) {
s = static_cast<char>(i);
......@@ -110,7 +110,7 @@ void BENCHFUN(assignmentFill)(int iters, int) {
}
BENCHMARK_PARAM(BENCHFUN(assignmentFill), 0);
void BENCHFUN(resize)(int iters, int arg) {
void BENCHFUN(resize)(size_t iters, size_t arg) {
STRING s;
FOR_EACH_RANGE (i, 0, iters) {
s.resize(random(0, arg));
......@@ -119,7 +119,7 @@ void BENCHFUN(resize)(int iters, int arg) {
}
BENCHMARK_PARAM(BENCHFUN(resize), 524288);
void BENCHFUN(findSuccessful)(int iters, int arg) {
void BENCHFUN(findSuccessful)(size_t iters, size_t arg) {
size_t pos, len;
STRING s;
......@@ -158,7 +158,7 @@ expect to get a call for an interview.";
}
BENCHMARK_PARAM(BENCHFUN(findSuccessful), 524288);
void BENCHFUN(findUnsuccessful)(int iters, int arg) {
void BENCHFUN(findUnsuccessful)(size_t iters, size_t arg) {
STRING s, s1;
BENCHMARK_SUSPEND {
......@@ -192,7 +192,7 @@ expect to get a call for an interview.";
}
BENCHMARK_PARAM(BENCHFUN(findUnsuccessful), 524288);
void BENCHFUN(equality)(int iters, int arg) {
void BENCHFUN(equality)(size_t iters, size_t arg) {
std::vector<STRING> haystack(arg);
BENCHMARK_SUSPEND {
......@@ -209,7 +209,7 @@ void BENCHFUN(equality)(int iters, int arg) {
}
BENCHMARK_PARAM(BENCHFUN(equality), 65536);
void BENCHFUN(replace)(int iters, int arg) {
void BENCHFUN(replace)(size_t iters, size_t arg) {
STRING s;
BENCHMARK_SUSPEND {
randomString(&s, arg);
......@@ -229,7 +229,7 @@ void BENCHFUN(replace)(int iters, int arg) {
}
BENCHMARK_PARAM(BENCHFUN(replace), 256);
void BENCHFUN(push_back)(int iters, int arg) {
void BENCHFUN(push_back)(size_t iters, size_t arg) {
FOR_EACH_RANGE (i, 0, iters) {
STRING s;
FOR_EACH_RANGE (j, 0, arg) {
......@@ -242,7 +242,7 @@ BENCHMARK_PARAM(BENCHFUN(push_back), 23);
BENCHMARK_PARAM(BENCHFUN(push_back), 127);
BENCHMARK_PARAM(BENCHFUN(push_back), 1024);
void BENCHFUN(short_append)(int iters, int arg) {
void BENCHFUN(short_append)(size_t iters, size_t arg) {
FOR_EACH_RANGE (i, 0, iters) {
STRING s;
FOR_EACH_RANGE (j, 0, arg) {
......
......@@ -88,7 +88,7 @@ ssize_t Reader::operator()(int fd, void* buf, size_t count) {
if (n <= 0) {
return n;
}
if (n > count) {
if (size_t(n) > count) {
throw std::runtime_error("requested count too small");
}
memcpy(buf, data_.data(), n);
......@@ -160,7 +160,7 @@ TEST_F(FileUtilTest, read) {
for (auto& p : readers_) {
std::string out(in_.size(), '\0');
EXPECT_EQ(p.first, wrapFull(p.second, 0, &out[0], out.size()));
if (p.first != -1) {
if (p.first != (typeof(p.first))(-1)) {
EXPECT_EQ(in_.substr(0, p.first), out.substr(0, p.first));
}
}
......@@ -170,7 +170,7 @@ TEST_F(FileUtilTest, pread) {
for (auto& p : readers_) {
std::string out(in_.size(), '\0');
EXPECT_EQ(p.first, wrapFull(p.second, 0, &out[0], out.size(), off_t(42)));
if (p.first != -1) {
if (p.first != (typeof(p.first))(-1)) {
EXPECT_EQ(in_.substr(0, p.first), out.substr(0, p.first));
}
}
......@@ -217,7 +217,7 @@ TEST_F(FileUtilTest, readv) {
auto iov = buf.iov();
EXPECT_EQ(p.first, wrapvFull(p.second, 0, iov.data(), iov.size()));
if (p.first != -1) {
if (p.first != (typeof(p.first))(-1)) {
EXPECT_EQ(in_.substr(0, p.first), buf.join().substr(0, p.first));
}
}
......@@ -232,7 +232,7 @@ TEST_F(FileUtilTest, preadv) {
auto iov = buf.iov();
EXPECT_EQ(p.first,
wrapvFull(p.second, 0, iov.data(), iov.size(), off_t(42)));
if (p.first != -1) {
if (p.first != (typeof(p.first))(-1)) {
EXPECT_EQ(in_.substr(0, p.first), buf.join().substr(0, p.first));
}
}
......
......@@ -175,9 +175,9 @@ TEST(Foreach, ForEachRangeR) {
std::map<int, std::string> bmMap; // For use in benchmarks below.
void setupBenchmark(int iters) {
void setupBenchmark(size_t iters) {
bmMap.clear();
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
bmMap[i] = "teststring";
}
}
......@@ -242,7 +242,7 @@ BENCHMARK(ForEachKVMacro, iters) {
BENCHMARK(ForEachManual, iters) {
int sum = 1;
for (auto i = 1; i < iters; ++i) {
for (size_t i = 1; i < iters; ++i) {
sum *= i;
}
doNotOptimizeAway(sum);
......@@ -258,7 +258,7 @@ BENCHMARK(ForEachRange, iters) {
BENCHMARK(ForEachDescendingManual, iters) {
int sum = 1;
for (auto i = iters; i-- > 1; ) {
for (size_t i = iters; i-- > 1; ) {
sum *= i;
}
doNotOptimizeAway(sum);
......
......@@ -726,7 +726,7 @@ TEST(IPAddress, SolicitedNodeAddress) {
TEST_P(IPAddressByteAccessorTest, CheckBytes) {
auto addrData = GetParam();
IPAddress ip(addrData.address);
auto i = 0;
size_t i = 0;
for (auto byitr = addrData.bytes.begin(); i < ip.byteCount(); ++i, ++byitr) {
EXPECT_EQ(*byitr, ip.getNthMSByte(i));
EXPECT_EQ(*byitr, ip.isV4() ?
......@@ -750,7 +750,7 @@ TEST_P(IPAddressBitAccessorTest, CheckBits) {
//We will traverse the IPAddress bits from 0 to bitCount -1
auto bitr = folly::makeBitIterator(littleEndianAddrData.begin());
IPAddress ip(addrData.address);
for (auto i = 0; i < ip.bitCount(); ++i) {
for (size_t i = 0; i < ip.bitCount(); ++i) {
auto msbIndex = ip.bitCount() - i - 1;
EXPECT_EQ(*bitr, ip.getNthMSBit(msbIndex));
EXPECT_EQ(*bitr, ip.isV4() ? ip.asV4().getNthMSBit(msbIndex) :
......
......@@ -400,7 +400,7 @@ TEST(Json, StripComments) {
BENCHMARK(jsonSerialize, iters) {
folly::json::serialization_opts opts;
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
folly::json::serialize(
"qwerty \xc2\x80 \xef\xbf\xbf poiuy"
"qwerty \xc2\x80 \xef\xbf\xbf poiuy"
......@@ -420,7 +420,7 @@ BENCHMARK(jsonSerializeWithNonAsciiEncoding, iters) {
folly::json::serialization_opts opts;
opts.encode_non_ascii = true;
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
folly::json::serialize(
"qwerty \xc2\x80 \xef\xbf\xbf poiuy"
"qwerty \xc2\x80 \xef\xbf\xbf poiuy"
......@@ -440,7 +440,7 @@ BENCHMARK(jsonSerializeWithUtf8Validation, iters) {
folly::json::serialization_opts opts;
opts.validate_utf8 = true;
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
folly::json::serialize(
"qwerty \xc2\x80 \xef\xbf\xbf poiuy"
"qwerty \xc2\x80 \xef\xbf\xbf poiuy"
......@@ -457,19 +457,19 @@ BENCHMARK(jsonSerializeWithUtf8Validation, iters) {
}
BENCHMARK(parseSmallStringWithUtf, iters) {
for (int i = 0; i < iters << 4; ++i) {
for (size_t i = 0; i < iters << 4; ++i) {
parseJson("\"I \\u2665 UTF-8 thjasdhkjh blah blah blah\"");
}
}
BENCHMARK(parseNormalString, iters) {
for (int i = 0; i < iters << 4; ++i) {
for (size_t i = 0; i < iters << 4; ++i) {
parseJson("\"akjhfk jhkjlakjhfk jhkjlakjhfk jhkjl akjhfk\"");
}
}
BENCHMARK(parseBigString, iters) {
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
parseJson("\""
"akjhfk jhkjlakjhfk jhkjlakjhfk jhkjl akjhfk"
"akjhfk jhkjlakjhfk jhkjlakjhfk jhkjl akjhfk"
......@@ -491,7 +491,7 @@ BENCHMARK(toJson, iters) {
"{\"old_value\":40,\"changed\":true,\"opened\":false,\"foo\":[1,2,3,4,5,6]}"
);
for (int i = 0; i < iters; i++) {
for (size_t i = 0; i < iters; i++) {
toJson(something);
}
}
......
......@@ -289,12 +289,12 @@ BENCHMARK(lifo_sem_pingpong, iters) {
LifoSem a;
LifoSem b;
auto thr = std::thread([&]{
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
a.wait();
b.post();
}
});
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
a.post();
b.wait();
}
......@@ -304,11 +304,11 @@ BENCHMARK(lifo_sem_pingpong, iters) {
BENCHMARK(lifo_sem_oneway, iters) {
LifoSem a;
auto thr = std::thread([&]{
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
a.wait();
}
});
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
a.post();
}
thr.join();
......@@ -316,7 +316,7 @@ BENCHMARK(lifo_sem_oneway, iters) {
BENCHMARK(single_thread_lifo_post, iters) {
LifoSem sem;
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
sem.post();
asm volatile ("":::"memory");
}
......@@ -324,7 +324,7 @@ BENCHMARK(single_thread_lifo_post, iters) {
BENCHMARK(single_thread_lifo_wait, iters) {
LifoSem sem(iters);
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
sem.wait();
asm volatile ("":::"memory");
}
......@@ -332,7 +332,7 @@ BENCHMARK(single_thread_lifo_wait, iters) {
BENCHMARK(single_thread_lifo_postwait, iters) {
LifoSem sem;
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
sem.post();
asm volatile ("":::"memory");
sem.wait();
......@@ -342,7 +342,7 @@ BENCHMARK(single_thread_lifo_postwait, iters) {
BENCHMARK(single_thread_lifo_trywait, iters) {
LifoSem sem;
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
EXPECT_FALSE(sem.tryWait());
asm volatile ("":::"memory");
}
......@@ -351,7 +351,7 @@ BENCHMARK(single_thread_lifo_trywait, iters) {
BENCHMARK(single_thread_posix_postwait, iters) {
sem_t sem;
EXPECT_EQ(sem_init(&sem, 0, 0), 0);
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
EXPECT_EQ(sem_post(&sem), 0);
EXPECT_EQ(sem_wait(&sem), 0);
}
......@@ -361,7 +361,7 @@ BENCHMARK(single_thread_posix_postwait, iters) {
BENCHMARK(single_thread_posix_trywait, iters) {
sem_t sem;
EXPECT_EQ(sem_init(&sem, 0, 0), 0);
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
EXPECT_EQ(sem_trywait(&sem), -1);
}
EXPECT_EQ(sem_destroy(&sem), 0);
......
......@@ -30,7 +30,7 @@ TEST(LogEveryMs, basic) {
}
bool atLeastOneIsGood = false;
for (int i = 0; i < hist.size() - 1; ++i) {
for (size_t i = 0; i < hist.size() - 1; ++i) {
auto delta = hist[i + 1] - hist[i];
if (delta > std::chrono::milliseconds(5) &&
delta < std::chrono::milliseconds(15)) {
......
......@@ -175,7 +175,7 @@ TEST(MPMCQueue, single_thread_enqdeq) {
TEST(MPMCQueue, tryenq_capacity_test) {
for (size_t cap = 1; cap < 100; ++cap) {
MPMCQueue<int> cq(cap);
for (int i = 0; i < cap; ++i) {
for (size_t i = 0; i < cap; ++i) {
EXPECT_TRUE(cq.write(i));
}
EXPECT_FALSE(cq.write(100));
......
......@@ -88,7 +88,7 @@ class IntPaddedConstTest : public IntPaddedTestBase {
v_.resize(4);
n_ = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < IntNode::kElementCount; ++j, ++n_) {
for (size_t j = 0; j < IntNode::kElementCount; ++j, ++n_) {
v_[i].data()[j] = n_;
}
}
......@@ -160,7 +160,7 @@ TEST_F(IntPaddedNonConstTest, Iteration) {
k = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < IntNode::kElementCount; ++j, ++k) {
for (size_t j = 0; j < IntNode::kElementCount; ++j, ++k) {
EXPECT_EQ(k, v_[i].data()[j]);
}
}
......@@ -185,7 +185,7 @@ class StructPaddedConstTest : public StructPaddedTestBase {
v_.resize(4);
n_ = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < PointNode::kElementCount; ++j, ++n_) {
for (size_t j = 0; j < PointNode::kElementCount; ++j, ++n_) {
auto& point = v_[i].data()[j];
point.x = n_;
point.y = n_ + 1;
......
......@@ -90,7 +90,7 @@ void initDelims(int len) {
s.push_back('a');
ffoTestString = s;
for (int i = 0; i < ffoDelimSize; ++i) {
for (size_t i = 0; i < ffoDelimSize; ++i) {
// most delimiter sets are pretty small, but occasionally there could
// be a big one.
auto n = rnd() % 8 + 1;
......@@ -293,7 +293,7 @@ BENCHMARK_DRAW_LINE();
template <class Func>
void findFirstOfRandom(Func func, size_t iters) {
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
auto test = i % ffoDelim.size();
auto p = func(ffoTestString, ffoDelim[test]);
doNotOptimizeAway(p);
......
......@@ -895,7 +895,7 @@ TYPED_TEST(NeedleFinderTest, Empty) {
TYPED_TEST(NeedleFinderTest, Unaligned) {
// works correctly even if input buffers are not 16-byte aligned
string s = "0123456789ABCDEFGH";
for (int i = 0; i < s.size(); ++i) {
for (size_t i = 0; i < s.size(); ++i) {
StringPiece a(s.c_str() + i);
for (int j = 0; j < s.size(); ++j) {
StringPiece b(s.c_str() + j);
......@@ -912,23 +912,23 @@ TYPED_TEST(NeedleFinderTest, Needles256) {
const auto maxValue = std::numeric_limits<StringPiece::value_type>::max();
// make the size ~big to avoid any edge-case branches for tiny haystacks
const int haystackSize = 50;
for (int i = minValue; i <= maxValue; i++) { // <=
for (size_t i = minValue; i <= maxValue; i++) { // <=
needles.push_back(i);
}
EXPECT_EQ(StringPiece::npos, this->find_first_byte_of("", needles));
for (int i = minValue; i <= maxValue; i++) {
for (size_t i = minValue; i <= maxValue; i++) {
EXPECT_EQ(0, this->find_first_byte_of(string(haystackSize, i), needles));
}
needles.append("these are redundant characters");
EXPECT_EQ(StringPiece::npos, this->find_first_byte_of("", needles));
for (int i = minValue; i <= maxValue; i++) {
for (size_t i = minValue; i <= maxValue; i++) {
EXPECT_EQ(0, this->find_first_byte_of(string(haystackSize, i), needles));
}
}
TYPED_TEST(NeedleFinderTest, Base) {
for (int i = 0; i < 32; ++i) {
for (size_t i = 0; i < 32; ++i) {
for (int j = 0; j < 32; ++j) {
string s = string(i, 'X') + "abca" + string(i, 'X');
string delims = string(j, 'Y') + "a" + string(j, 'Y');
......@@ -1047,10 +1047,11 @@ TEST(RangeFunc, CArray) {
testRangeFunc(x, 4);
}
std::string get_rand_str(
int size, std::uniform_int_distribution<>& dist, std::mt19937& gen) {
std::string get_rand_str(size_t size,
std::uniform_int_distribution<>& dist,
std::mt19937& gen) {
std::string ret(size, '\0');
for (int i=0; i<size; ++i) {
for (size_t i = 0; i < size; ++i) {
ret[i] = static_cast<char>(dist(gen));
}
......@@ -1076,9 +1077,9 @@ TEST(ReplaceAt, exhaustiveTest) {
std::uniform_int_distribution<> dist('a', 'z');
for (int i=0; i < 100; ++i) {
for (int j = 1; j <= msp.size(); ++j) {
for (size_t j = 1; j <= msp.size(); ++j) {
auto replacement = get_rand_str(j, dist, gen);
for (int pos=0; pos < msp.size() - j; ++pos) {
for (size_t pos = 0; pos < msp.size() - j; ++pos) {
msp.replaceAt(pos, replacement);
str.replace(pos, replacement.size(), replacement);
EXPECT_EQ(msp.compare(str), 0);
......@@ -1132,9 +1133,9 @@ TEST(ReplaceAll, randomTest) {
std::uniform_int_distribution<> dist('A', 'Z');
for (int i=0; i < 100; ++i) {
for (int j = 1; j <= orig.size(); ++j) {
for (size_t j = 1; j <= orig.size(); ++j) {
auto replacement = get_rand_str(j, dist, gen);
for (int pos=0; pos < msp.size() - j; ++pos) {
for (size_t pos = 0; pos < msp.size() - j; ++pos) {
auto piece = orig.substr(pos, j);
EXPECT_EQ(msp.replaceAll(piece, replacement), 1);
EXPECT_EQ(msp.find(replacement), pos);
......
......@@ -64,7 +64,7 @@ void splock_test() {
MSLGuard g(v.lock);
int first = v.ar[0];
for (int i = 1; i < sizeof v.ar / sizeof i; ++i) {
for (size_t i = 1; i < sizeof v.ar / sizeof i; ++i) {
EXPECT_EQ(first, v.ar[i]);
}
......
......@@ -1203,7 +1203,7 @@ TEST(String, toLowerAsciiUnaligned) {
BENCHMARK(splitOnSingleChar, iters) {
static const std::string line = "one:two:three:four";
for (int i = 0; i < iters << 4; ++i) {
for (size_t i = 0; i < iters << 4; ++i) {
std::vector<StringPiece> pieces;
folly::split(':', line, pieces);
}
......@@ -1211,7 +1211,7 @@ BENCHMARK(splitOnSingleChar, iters) {
BENCHMARK(splitOnSingleCharFixed, iters) {
static const std::string line = "one:two:three:four";
for (int i = 0; i < iters << 4; ++i) {
for (size_t i = 0; i < iters << 4; ++i) {
StringPiece a, b, c, d;
folly::split(':', line, a, b, c, d);
}
......@@ -1219,7 +1219,7 @@ BENCHMARK(splitOnSingleCharFixed, iters) {
BENCHMARK(splitOnSingleCharFixedAllowExtra, iters) {
static const std::string line = "one:two:three:four";
for (int i = 0; i < iters << 4; ++i) {
for (size_t i = 0; i < iters << 4; ++i) {
StringPiece a, b, c, d;
folly::split<false>(':', line, a, b, c, d);
}
......@@ -1227,7 +1227,7 @@ BENCHMARK(splitOnSingleCharFixedAllowExtra, iters) {
BENCHMARK(splitStr, iters) {
static const std::string line = "one-*-two-*-three-*-four";
for (int i = 0; i < iters << 4; ++i) {
for (size_t i = 0; i < iters << 4; ++i) {
std::vector<StringPiece> pieces;
folly::split("-*-", line, pieces);
}
......@@ -1235,7 +1235,7 @@ BENCHMARK(splitStr, iters) {
BENCHMARK(splitStrFixed, iters) {
static const std::string line = "one-*-two-*-three-*-four";
for (int i = 0; i < iters << 4; ++i) {
for (size_t i = 0; i < iters << 4; ++i) {
StringPiece a, b, c, d;
folly::split("-*-", line, a, b, c, d);
}
......@@ -1244,7 +1244,7 @@ BENCHMARK(splitStrFixed, iters) {
BENCHMARK(boost_splitOnSingleChar, iters) {
static const std::string line = "one:two:three:four";
bool(*pred)(char) = [] (char c) -> bool { return c == ':'; };
for (int i = 0; i < iters << 4; ++i) {
for (size_t i = 0; i < iters << 4; ++i) {
std::vector<boost::iterator_range<std::string::const_iterator> > pieces;
boost::split(pieces, line, pred);
}
......@@ -1253,7 +1253,7 @@ BENCHMARK(boost_splitOnSingleChar, iters) {
BENCHMARK(joinCharStr, iters) {
static const std::vector<std::string> input = {
"one", "two", "three", "four", "five", "six", "seven" };
for (int i = 0; i < iters << 4; ++i) {
for (size_t i = 0; i < iters << 4; ++i) {
std::string output;
folly::join(':', input, output);
}
......@@ -1262,7 +1262,7 @@ BENCHMARK(joinCharStr, iters) {
BENCHMARK(joinStrStr, iters) {
static const std::vector<std::string> input = {
"one", "two", "three", "four", "five", "six", "seven" };
for (int i = 0; i < iters << 4; ++i) {
for (size_t i = 0; i < iters << 4; ++i) {
std::string output;
folly::join(":", input, output);
}
......@@ -1271,7 +1271,7 @@ BENCHMARK(joinStrStr, iters) {
BENCHMARK(joinInt, iters) {
static const auto input = {
123, 456, 78910, 1112, 1314, 151, 61718 };
for (int i = 0; i < iters << 4; ++i) {
for (size_t i = 0; i < iters << 4; ++i) {
std::string output;
folly::join(":", input, output);
}
......
......@@ -262,7 +262,7 @@ TEST(CommunicateSubprocessTest, Duplex2) {
const size_t numCopies = 100000;
auto iobuf = IOBuf::copyBuffer("this is a test\nanother line\n");
IOBufQueue input;
for (int n = 0; n < numCopies; ++n) {
for (size_t n = 0; n < numCopies; ++n) {
input.append(iobuf->clone());
}
......
......@@ -404,14 +404,14 @@ TEST(Uri, Simple) {
*/
BENCHMARK(init_uri_simple, iters) {
const fbstring s("http://localhost?&key1=foo&key2=&key3&=bar&=bar=&");
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
Uri u(s);
}
}
BENCHMARK(init_uri_simple_with_query_parsing, iters) {
const fbstring s("http://localhost?&key1=foo&key2=&key3&=bar&=bar=&");
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
Uri u(s);
u.getQueryParams();
}
......@@ -429,7 +429,7 @@ BENCHMARK(init_uri_complex, iters) {
"04nYX8N%46zzpv%999h&KGmBt988y=q4P57C-Dh-Nz-x_7-5oPxz%1gz3N03t6c7-R67N4DT"
"Y6-f98W1&Lts&%02dOty%8eEYEnLz4yexQQLnL4MGU2JFn3OcmXcatBcabZgBdDdy67hdgW"
"tYn4");
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
Uri u(s);
}
}
......@@ -446,7 +446,7 @@ BENCHMARK(init_uri_complex_with_query_parsing, iters) {
"04nYX8N%46zzpv%999h&KGmBt988y=q4P57C-Dh-Nz-x_7-5oPxz%1gz3N03t6c7-R67N4DT"
"Y6-f98W1&Lts&%02dOty%8eEYEnLz4yexQQLnL4MGU2JFn3OcmXcatBcabZgBdDdy67hdgW"
"tYn4");
for (int i = 0; i < iters; ++i) {
for (size_t i = 0; i < iters; ++i) {
Uri u(s);
u.getQueryParams();
}
......
......@@ -115,7 +115,7 @@ void generateRandomValues() {
for (size_t i = 0; i < kNumValues; ++i) {
int n = numBytes(rng);
uint64_t val = 0;
for (size_t j = 0; j < n; ++j) {
for (int j = 0; j < n; ++j) {
val = (val << 8) + byte(rng);
}
gValues[i] = val;
......
......@@ -30,7 +30,7 @@ DECLARE_int32(bm_max_iters);
// Directly invoking a function
BENCHMARK(fn_invoke, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
doNothing();
}
}
......@@ -97,7 +97,7 @@ BENCHMARK(virtual_fn_invoke, iters) {
// Creating a function pointer and invoking it
BENCHMARK(fn_ptr_create_invoke, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
void (*fn)() = doNothing;
fn();
}
......@@ -105,7 +105,7 @@ BENCHMARK(fn_ptr_create_invoke, iters) {
// Creating a std::function object from a function pointer, and invoking it
BENCHMARK(std_function_create_invoke, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
std::function<void()> fn = doNothing;
fn();
}
......@@ -114,7 +114,7 @@ BENCHMARK(std_function_create_invoke, iters) {
// Creating a pointer-to-member and invoking it
BENCHMARK(mem_fn_create_invoke, iters) {
TestClass tc;
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
void (TestClass::*memfn)() = &TestClass::doNothing;
(tc.*memfn)();
}
......@@ -124,7 +124,7 @@ BENCHMARK(mem_fn_create_invoke, iters) {
// and invoking it
BENCHMARK(std_bind_create_invoke, iters) {
TestClass tc;
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
std::function<void()> fn = std::bind(&TestClass::doNothing, &tc);
fn();
}
......@@ -133,7 +133,7 @@ BENCHMARK(std_bind_create_invoke, iters) {
// Using std::bind directly to invoke a member function
BENCHMARK(std_bind_direct_invoke, iters) {
TestClass tc;
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
auto fn = std::bind(&TestClass::doNothing, &tc);
fn();
}
......@@ -142,7 +142,7 @@ BENCHMARK(std_bind_direct_invoke, iters) {
// Using ScopeGuard to invoke a std::function
BENCHMARK(scope_guard_std_function, iters) {
std::function<void()> fn(doNothing);
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard(fn);
}
}
......@@ -150,28 +150,28 @@ BENCHMARK(scope_guard_std_function, iters) {
// Using ScopeGuard to invoke a std::function,
// but create the ScopeGuard with an rvalue to a std::function
BENCHMARK(scope_guard_std_function_rvalue, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard(std::function<void()>(doNothing));
}
}
// Using ScopeGuard to invoke a function pointer
BENCHMARK(scope_guard_fn_ptr, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard(doNothing);
}
}
// Using ScopeGuard to invoke a lambda that does nothing
BENCHMARK(scope_guard_lambda_noop, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard([] {});
}
}
// Using ScopeGuard to invoke a lambda that invokes a function
BENCHMARK(scope_guard_lambda_function, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard([] { doNothing(); });
}
}
......@@ -179,7 +179,7 @@ BENCHMARK(scope_guard_lambda_function, iters) {
// Using ScopeGuard to invoke a lambda that modifies a local variable
BENCHMARK(scope_guard_lambda_local_var, iters) {
uint32_t count = 0;
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard([&] {
// Increment count if n is odd. Without this conditional check
// (i.e., if we just increment count each time through the loop),
......@@ -200,7 +200,7 @@ BENCHMARK(scope_guard_lambda_local_var, iters) {
BENCHMARK_DRAW_LINE()
BENCHMARK(throw_exception, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
try {
throwException();
} catch (const std::exception& ex) {
......@@ -209,7 +209,7 @@ BENCHMARK(throw_exception, iters) {
}
BENCHMARK(catch_no_exception, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
try {
doNothing();
} catch (const std::exception& ex) {
......@@ -218,44 +218,44 @@ BENCHMARK(catch_no_exception, iters) {
}
BENCHMARK(return_exc_ptr, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
returnExceptionPtr();
}
}
BENCHMARK(exc_ptr_param_return, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
std::exception_ptr ex;
exceptionPtrReturnParam(&ex);
}
}
BENCHMARK(exc_ptr_param_return_null, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
exceptionPtrReturnParam(nullptr);
}
}
BENCHMARK(return_string, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
returnString();
}
}
BENCHMARK(return_string_noexcept, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
returnStringNoExcept();
}
}
BENCHMARK(return_code, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
returnCode(false);
}
}
BENCHMARK(return_code_noexcept, iters) {
for (int n = 0; n < iters; ++n) {
for (size_t n = 0; n < iters; ++n) {
returnCodeNoExcept(false);
}
}
......
......@@ -284,7 +284,7 @@ TEST(small_vector, Insert) {
folly::small_vector<int> someVec(3, 3);
someVec.insert(someVec.begin(), 12, 12);
EXPECT_EQ(someVec.size(), 15);
for (int i = 0; i < someVec.size(); ++i) {
for (size_t i = 0; i < someVec.size(); ++i) {
if (i < 12) {
EXPECT_EQ(someVec[i], 12);
} else {
......@@ -424,7 +424,7 @@ TEST(small_vector, GrowShrinkGrow) {
auto capacity = vec.capacity();
auto oldSize = vec.size();
for (int i = 0; i < oldSize; ++i) {
for (size_t i = 0; i < oldSize; ++i) {
vec.erase(vec.begin() + (std::rand() % vec.size()));
EXPECT_EQ(vec.capacity(), capacity);
}
......
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