From 7ffe7766f032914384aa6e0b9598bab7d9a90602 Mon Sep 17 00:00:00 2001 From: Daniel Sommermann Date: Mon, 20 Oct 2014 12:52:01 -0700 Subject: [PATCH] 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 --- folly/Benchmark.h | 7 ++-- folly/IPAddressV6.cpp | 2 +- folly/Random.cpp | 3 +- folly/String.cpp | 4 +- folly/Subprocess.cpp | 4 +- folly/Varint.h | 3 +- folly/detail/CacheLocality.cpp | 6 +-- .../exception_tracer/ExceptionTracer.cpp | 2 +- folly/experimental/io/test/AsyncIOTest.cpp | 18 ++++---- .../experimental/symbolizer/SignalHandler.cpp | 2 +- folly/experimental/symbolizer/StackTrace.cpp | 2 +- folly/experimental/test/SingletonTest.cpp | 6 +-- .../concurrent/CPUThreadPoolExecutor.cpp | 2 +- .../concurrent/IOThreadPoolExecutor.cpp | 2 +- .../wangle/concurrent/ThreadPoolExecutor.cpp | 4 +- folly/gen/test/FileBenchmark.cpp | 4 +- folly/gen/test/ParallelMapBenchmark.cpp | 2 +- folly/gen/test/StringTest.cpp | 2 +- folly/io/Compression.cpp | 2 +- folly/io/Cursor-defs.h | 4 +- folly/io/RecordIO.cpp | 3 +- folly/io/ShutdownSocketSet.cpp | 8 ++-- folly/io/async/AsyncSocket.cpp | 2 +- folly/io/test/IOBufQueueTest.cpp | 4 +- folly/io/test/RecordIOTest.cpp | 4 +- folly/test/AtomicHashMapTest.cpp | 33 ++++++++------- folly/test/BatonTest.cpp | 4 +- folly/test/ConcurrentSkipListBenchmark.cpp | 16 +++---- folly/test/ConcurrentSkipListTest.cpp | 2 +- folly/test/ConvTest.cpp | 4 +- folly/test/DeterministicSchedule.cpp | 14 +++---- folly/test/ExceptionWrapperBenchmark.cpp | 20 ++++----- folly/test/FBStringTestBenchmarks.cpp.h | 30 ++++++------- folly/test/FileUtilTest.cpp | 10 ++--- folly/test/ForeachTest.cpp | 8 ++-- folly/test/IPAddressTest.cpp | 4 +- folly/test/JsonTest.cpp | 14 +++---- folly/test/LifoSemTests.cpp | 20 ++++----- folly/test/LoggingTest.cpp | 2 +- folly/test/MPMCQueueTest.cpp | 2 +- folly/test/PaddedTest.cpp | 6 +-- folly/test/RangeFindBenchmark.cpp | 4 +- folly/test/RangeTest.cpp | 25 +++++------ folly/test/SmallLocksTest.cpp | 2 +- folly/test/StringTest.cpp | 18 ++++---- folly/test/SubprocessTest.cpp | 2 +- folly/test/UriTest.cpp | 8 ++-- folly/test/VarintTest.cpp | 2 +- folly/test/function_benchmark/main.cpp | 42 +++++++++---------- folly/test/small_vector_test.cpp | 4 +- 50 files changed, 202 insertions(+), 196 deletions(-) diff --git a/folly/Benchmark.h b/folly/Benchmark.h index 04411f63..e8a7f0a6 100644 --- a/folly/Benchmark.h +++ b/folly/Benchmark.h @@ -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::max() / 1000000000UL); - return (end.tv_sec - start.tv_sec) * 1000000000UL + return diff * 1000000000UL + end.tv_nsec - start.tv_nsec; } diff --git a/folly/IPAddressV6.cpp b/folly/IPAddressV6.cpp index 1bf3a300..45e9e3a1 100644 --- a/folly/IPAddressV6.cpp +++ b/folly/IPAddressV6.cpp @@ -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; diff --git a/folly/Random.cpp b/folly/Random.cpp index f18d6f33..533ac407 100644 --- a/folly/Random.cpp +++ b/folly/Random.cpp @@ -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 { diff --git a/folly/String.cpp b/folly/String.cpp index b4573917..ce50ae1a 100644 --- a/folly/String.cpp +++ b/folly/String.cpp @@ -52,7 +52,7 @@ inline void stringPrintfImpl(std::string& output, const char* format, throw std::runtime_error( to("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("vsnprint retry did not manage to work " "with format string: ", format)); diff --git a/folly/Subprocess.cpp b/folly/Subprocess.cpp index c17e8849..11bbc3f7 100644 --- a/folly/Subprocess.cpp +++ b/folly/Subprocess.cpp @@ -118,7 +118,7 @@ namespace { // Copy pointers to the given strings in a format suitable for posix_spawn std::unique_ptr cloneStrings(const std::vector& s) { std::unique_ptr 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; diff --git a/folly/Varint.h b/folly/Varint.h index 7ce9d301..2f8739fe 100644 --- a/folly/Varint.h +++ b/folly/Varint.h @@ -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; diff --git a/folly/detail/CacheLocality.cpp b/folly/detail/CacheLocality.cpp index e7d992ae..7af5962f 100644 --- a/folly/detail/CacheLocality.cpp +++ b/folly/detail/CacheLocality.cpp @@ -80,10 +80,10 @@ const CacheLocality& CacheLocality::system() { /// 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( "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 indexes(cpus.size()); - for (int i = 0; i < cpus.size(); ++i) { + for (size_t i = 0; i < cpus.size(); ++i) { indexes[cpus[i]] = i; } diff --git a/folly/experimental/exception_tracer/ExceptionTracer.cpp b/folly/experimental/exception_tracer/ExceptionTracer.cpp index 81030dbf..c4e3b850 100644 --- a/folly/experimental/exception_tracer/ExceptionTracer.cpp +++ b/folly/experimental/exception_tracer/ExceptionTracer.cpp @@ -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; diff --git a/folly/experimental/io/test/AsyncIOTest.cpp b/folly/experimental/io/test/AsyncIOTest.cpp index c21691f6..721e5600 100644 --- a/folly/experimental/io/test/AsyncIOTest.cpp +++ b/folly/experimental/io/test/AsyncIOTest.cpp @@ -136,7 +136,7 @@ void testReadsSerially(const std::vector& 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& 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& 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& 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& 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& 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& 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]); } } diff --git a/folly/experimental/symbolizer/SignalHandler.cpp b/folly/experimental/symbolizer/SignalHandler.cpp index 952c7f33..2a98872e 100644 --- a/folly/experimental/symbolizer/SignalHandler.cpp +++ b/folly/experimental/symbolizer/SignalHandler.cpp @@ -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"); } diff --git a/folly/experimental/symbolizer/StackTrace.cpp b/folly/experimental/symbolizer/StackTrace.cpp index 863ccf5e..ee8c27e7 100644 --- a/folly/experimental/symbolizer/StackTrace.cpp +++ b/folly/experimental/symbolizer/StackTrace.cpp @@ -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) { diff --git a/folly/experimental/test/SingletonTest.cpp b/folly/experimental/test/SingletonTest.cpp index 3a42202f..821a41cb 100644 --- a/folly/experimental/test/SingletonTest.cpp +++ b/folly/experimental/test/SingletonTest.cpp @@ -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::get(&benchmark_vault)); } } diff --git a/folly/experimental/wangle/concurrent/CPUThreadPoolExecutor.cpp b/folly/experimental/wangle/concurrent/CPUThreadPoolExecutor.cpp index 715bd372..4ef20454 100644 --- a/folly/experimental/wangle/concurrent/CPUThreadPoolExecutor.cpp +++ b/folly/experimental/wangle/concurrent/CPUThreadPoolExecutor.cpp @@ -74,7 +74,7 @@ void CPUThreadPoolExecutor::threadRun(std::shared_ptr 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()); } } diff --git a/folly/experimental/wangle/concurrent/IOThreadPoolExecutor.cpp b/folly/experimental/wangle/concurrent/IOThreadPoolExecutor.cpp index db8ffdca..dfca6216 100644 --- a/folly/experimental/wangle/concurrent/IOThreadPoolExecutor.cpp +++ b/folly/experimental/wangle/concurrent/IOThreadPoolExecutor.cpp @@ -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( threadList_.get()[i]); ioThread->shouldRun = false; diff --git a/folly/experimental/wangle/concurrent/ThreadPoolExecutor.cpp b/folly/experimental/wangle/concurrent/ThreadPoolExecutor.cpp index 5924f736..18d8c275 100644 --- a/folly/experimental/wangle/concurrent/ThreadPoolExecutor.cpp +++ b/folly/experimental/wangle/concurrent/ThreadPoolExecutor.cpp @@ -85,7 +85,7 @@ void ThreadPoolExecutor::setNumThreads(size_t n) { // threadListLock_ is writelocked void ThreadPoolExecutor::addThreads(size_t n) { std::vector 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); diff --git a/folly/gen/test/FileBenchmark.cpp b/folly/gen/test/FileBenchmark.cpp index ac10fd18..243edc06 100644 --- a/folly/gen/test/FileBenchmark.cpp +++ b/folly/gen/test/FileBenchmark.cpp @@ -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); }); diff --git a/folly/gen/test/ParallelMapBenchmark.cpp b/folly/gen/test/ParallelMapBenchmark.cpp index a0b466c2..6bd2a2c0 100644 --- a/folly/gen/test/ParallelMapBenchmark.cpp +++ b/folly/gen/test/ParallelMapBenchmark.cpp @@ -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(); } diff --git a/folly/gen/test/StringTest.cpp b/folly/gen/test/StringTest.cpp index d6bb7122..3f28aa9a 100644 --- a/folly/gen/test/StringTest.cpp +++ b/folly/gen/test/StringTest.cpp @@ -275,7 +275,7 @@ void checkResplitMaxLength(vector 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]); } diff --git a/folly/io/Compression.cpp b/folly/io/Compression.cpp index f52d2e78..8c8fe61f 100644 --- a/folly/io/Compression.cpp +++ b/folly/io/Compression.cpp @@ -295,7 +295,7 @@ std::unique_ptr LZ4Codec::doUncompress( p.second, actualUncompressedLength); - if (n != actualUncompressedLength) { + if (n < 0 || uint64_t(n) != actualUncompressedLength) { throw std::runtime_error(to( "LZ4 decompression returned invalid value ", n)); } diff --git a/folly/io/Cursor-defs.h b/folly/io/Cursor-defs.h index 2ee9319d..9bee2098 100644 --- a/folly/io/Cursor-defs.h +++ b/folly/io/Cursor-defs.h @@ -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"); diff --git a/folly/io/RecordIO.cpp b/folly/io/RecordIO.cpp index 6aab5321..7f3ed6ef 100644 --- a/folly/io/RecordIO.cpp +++ b/folly/io/RecordIO.cpp @@ -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 { diff --git a/folly/io/ShutdownSocketSet.cpp b/folly/io/ShutdownSocketSet.cpp index 52125c25..95c27d36 100644 --- a/folly/io/ShutdownSocketSet.cpp +++ b/folly/io/ShutdownSocketSet.cpp @@ -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; } diff --git a/folly/io/async/AsyncSocket.cpp b/folly/io/async/AsyncSocket.cpp index 69cfe867..ceba5211 100644 --- a/folly/io/async/AsyncSocket.cpp +++ b/folly/io/async/AsyncSocket.cpp @@ -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) { diff --git a/folly/io/test/IOBufQueueTest.cpp b/folly/io/test/IOBufQueueTest.cpp index e1051a1e..9e7c5a44 100644 --- a/folly/io/test/IOBufQueueTest.cpp +++ b/folly/io/test/IOBufQueueTest.cpp @@ -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 first; - for(ssize_t i=0; icomputeChainDataLength()); EXPECT_EQ(chainLength, queue.chainLength()); diff --git a/folly/io/test/RecordIOTest.cpp b/folly/io/test/RecordIOTest.cpp index a9d06244..2b3a77d0 100644 --- a/folly/io/test/RecordIOTest.cpp +++ b/folly/io/test/RecordIOTest.cpp @@ -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)); } diff --git a/folly/test/AtomicHashMapTest.cpp b/folly/test/AtomicHashMapTest.cpp index a91f571f..9d57d621 100644 --- a/folly/test/AtomicHashMapTest.cpp +++ b/folly/test/AtomicHashMapTest.cpp @@ -90,7 +90,6 @@ TEST(Ahm, BasicNoncopyable) { } typedef int32_t KeyT; -typedef int64_t KeyTBig; typedef int32_t ValueT; typedef AtomicHashMap 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 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 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 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 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)); } diff --git a/folly/test/BatonTest.cpp b/folly/test/BatonTest.cpp index 8779a4c3..f663bf25 100644 --- a/folly/test/BatonTest.cpp +++ b/folly/test/BatonTest.cpp @@ -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); } diff --git a/folly/test/ConcurrentSkipListBenchmark.cpp b/folly/test/ConcurrentSkipListBenchmark.cpp index 951079b5..daaa3f7e 100644 --- a/folly/test/ConcurrentSkipListBenchmark.cpp +++ b/folly/test/ConcurrentSkipListBenchmark.cpp @@ -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(); } diff --git a/folly/test/ConcurrentSkipListTest.cpp b/folly/test/ConcurrentSkipListTest.cpp index f0139648..d41dbbc8 100644 --- a/folly/test/ConcurrentSkipListTest.cpp +++ b/folly/test/ConcurrentSkipListTest.cpp @@ -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(); } diff --git a/folly/test/ConvTest.cpp b/folly/test/ConvTest.cpp index d15b638d..31cd9eda 100644 --- a/folly/test/ConvTest.cpp +++ b/folly/test/ConvTest.cpp @@ -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(bigInt, someString, stdString, otherString); auto val3 = to(reallyShort, smallInt); auto val2 = to(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(stdString, ',', fValue, dValue); auto val2 = to(stdString, ',', dValue); } diff --git a/folly/test/DeterministicSchedule.cpp b/folly/test/DeterministicSchedule.cpp index a079917e..a0ab4380 100644 --- a/folly/test/DeterministicSchedule.cpp +++ b/folly/test/DeterministicSchedule.cpp @@ -58,7 +58,7 @@ DeterministicSchedule::~DeterministicSchedule() { std::function DeterministicSchedule::uniform(long seed) { auto rand = std::make_shared(seed); - return [rand](int numActive) { + return [rand](size_t numActive) { auto dist = std::uniform_int_distribution(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 uniform_; - const int subsetSize_; + const size_t subsetSize_; const int stepsBetweenSelect_; int stepsLeft_; // only the first subsetSize_ is properly randomized std::vector 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 DeterministicSchedule::uniformSubset(long seed, int n, int m) { auto gen = std::make_shared(seed, n, m); - return [=](int numActive) { return (*gen)(numActive); }; + return [=](size_t numActive) { return (*gen)(numActive); }; } void diff --git a/folly/test/ExceptionWrapperBenchmark.cpp b/folly/test/ExceptionWrapperBenchmark.cpp index e384be65..c1062526 100644 --- a/folly/test/ExceptionWrapperBenchmark.cpp +++ b/folly/test/ExceptionWrapperBenchmark.cpp @@ -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(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(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(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(e); assert(ew.is_compatible_with()); } @@ -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(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(e); assert(ew.is_compatible_with()); } diff --git a/folly/test/FBStringTestBenchmarks.cpp.h b/folly/test/FBStringTestBenchmarks.cpp.h index b59bb086..0b23fb21 100644 --- a/folly/test/FBStringTestBenchmarks.cpp.h +++ b/folly/test/FBStringTestBenchmarks.cpp.h @@ -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(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 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) { diff --git a/folly/test/FileUtilTest.cpp b/folly/test/FileUtilTest.cpp index 698320c0..3b5ca72f 100644 --- a/folly/test/FileUtilTest.cpp +++ b/folly/test/FileUtilTest.cpp @@ -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)); } } diff --git a/folly/test/ForeachTest.cpp b/folly/test/ForeachTest.cpp index a4fac00c..bff6b502 100644 --- a/folly/test/ForeachTest.cpp +++ b/folly/test/ForeachTest.cpp @@ -175,9 +175,9 @@ TEST(Foreach, ForEachRangeR) { std::map 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); diff --git a/folly/test/IPAddressTest.cpp b/folly/test/IPAddressTest.cpp index 4b655027..202661a6 100644 --- a/folly/test/IPAddressTest.cpp +++ b/folly/test/IPAddressTest.cpp @@ -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) : diff --git a/folly/test/JsonTest.cpp b/folly/test/JsonTest.cpp index 606e79a3..334164fa 100644 --- a/folly/test/JsonTest.cpp +++ b/folly/test/JsonTest.cpp @@ -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); } } diff --git a/folly/test/LifoSemTests.cpp b/folly/test/LifoSemTests.cpp index 7d034211..f561d2a5 100644 --- a/folly/test/LifoSemTests.cpp +++ b/folly/test/LifoSemTests.cpp @@ -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); diff --git a/folly/test/LoggingTest.cpp b/folly/test/LoggingTest.cpp index 11269253..d404bd34 100644 --- a/folly/test/LoggingTest.cpp +++ b/folly/test/LoggingTest.cpp @@ -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)) { diff --git a/folly/test/MPMCQueueTest.cpp b/folly/test/MPMCQueueTest.cpp index be1fbc90..50dcafef 100644 --- a/folly/test/MPMCQueueTest.cpp +++ b/folly/test/MPMCQueueTest.cpp @@ -175,7 +175,7 @@ TEST(MPMCQueue, single_thread_enqdeq) { TEST(MPMCQueue, tryenq_capacity_test) { for (size_t cap = 1; cap < 100; ++cap) { MPMCQueue 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)); diff --git a/folly/test/PaddedTest.cpp b/folly/test/PaddedTest.cpp index 324a91d4..bed71c98 100644 --- a/folly/test/PaddedTest.cpp +++ b/folly/test/PaddedTest.cpp @@ -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; diff --git a/folly/test/RangeFindBenchmark.cpp b/folly/test/RangeFindBenchmark.cpp index eecbf9c3..306aa7ab 100644 --- a/folly/test/RangeFindBenchmark.cpp +++ b/folly/test/RangeFindBenchmark.cpp @@ -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 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); diff --git a/folly/test/RangeTest.cpp b/folly/test/RangeTest.cpp index afc8ec8a..a8f2c615 100644 --- a/folly/test/RangeTest.cpp +++ b/folly/test/RangeTest.cpp @@ -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::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(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); diff --git a/folly/test/SmallLocksTest.cpp b/folly/test/SmallLocksTest.cpp index f0fd291d..bafb6832 100644 --- a/folly/test/SmallLocksTest.cpp +++ b/folly/test/SmallLocksTest.cpp @@ -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]); } diff --git a/folly/test/StringTest.cpp b/folly/test/StringTest.cpp index e24f3028..23ee318a 100644 --- a/folly/test/StringTest.cpp +++ b/folly/test/StringTest.cpp @@ -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 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(':', 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 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 > pieces; boost::split(pieces, line, pred); } @@ -1253,7 +1253,7 @@ BENCHMARK(boost_splitOnSingleChar, iters) { BENCHMARK(joinCharStr, iters) { static const std::vector 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 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); } diff --git a/folly/test/SubprocessTest.cpp b/folly/test/SubprocessTest.cpp index a2ffc8dc..283928de 100644 --- a/folly/test/SubprocessTest.cpp +++ b/folly/test/SubprocessTest.cpp @@ -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()); } diff --git a/folly/test/UriTest.cpp b/folly/test/UriTest.cpp index d16242d6..97967203 100644 --- a/folly/test/UriTest.cpp +++ b/folly/test/UriTest.cpp @@ -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(); } diff --git a/folly/test/VarintTest.cpp b/folly/test/VarintTest.cpp index 91da0536..546ebc3e 100644 --- a/folly/test/VarintTest.cpp +++ b/folly/test/VarintTest.cpp @@ -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; diff --git a/folly/test/function_benchmark/main.cpp b/folly/test/function_benchmark/main.cpp index 13d8a67f..e58047dc 100644 --- a/folly/test/function_benchmark/main.cpp +++ b/folly/test/function_benchmark/main.cpp @@ -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 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 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 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(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); } } diff --git a/folly/test/small_vector_test.cpp b/folly/test/small_vector_test.cpp index f80a4605..0e014a2c 100644 --- a/folly/test/small_vector_test.cpp +++ b/folly/test/small_vector_test.cpp @@ -284,7 +284,7 @@ TEST(small_vector, Insert) { folly::small_vector 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); } -- 2.34.1