Fix -Wsign-compare
authorDaniel Sommermann <dcsommer@fb.com>
Mon, 20 Oct 2014 19:52:01 +0000 (12:52 -0700)
committerPavlo Kushnir <pavlo@fb.com>
Sat, 8 Nov 2014 02:29:16 +0000 (18:29 -0800)
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

50 files changed:
folly/Benchmark.h
folly/IPAddressV6.cpp
folly/Random.cpp
folly/String.cpp
folly/Subprocess.cpp
folly/Varint.h
folly/detail/CacheLocality.cpp
folly/experimental/exception_tracer/ExceptionTracer.cpp
folly/experimental/io/test/AsyncIOTest.cpp
folly/experimental/symbolizer/SignalHandler.cpp
folly/experimental/symbolizer/StackTrace.cpp
folly/experimental/test/SingletonTest.cpp
folly/experimental/wangle/concurrent/CPUThreadPoolExecutor.cpp
folly/experimental/wangle/concurrent/IOThreadPoolExecutor.cpp
folly/experimental/wangle/concurrent/ThreadPoolExecutor.cpp
folly/gen/test/FileBenchmark.cpp
folly/gen/test/ParallelMapBenchmark.cpp
folly/gen/test/StringTest.cpp
folly/io/Compression.cpp
folly/io/Cursor-defs.h
folly/io/RecordIO.cpp
folly/io/ShutdownSocketSet.cpp
folly/io/async/AsyncSocket.cpp
folly/io/test/IOBufQueueTest.cpp
folly/io/test/RecordIOTest.cpp
folly/test/AtomicHashMapTest.cpp
folly/test/BatonTest.cpp
folly/test/ConcurrentSkipListBenchmark.cpp
folly/test/ConcurrentSkipListTest.cpp
folly/test/ConvTest.cpp
folly/test/DeterministicSchedule.cpp
folly/test/ExceptionWrapperBenchmark.cpp
folly/test/FBStringTestBenchmarks.cpp.h
folly/test/FileUtilTest.cpp
folly/test/ForeachTest.cpp
folly/test/IPAddressTest.cpp
folly/test/JsonTest.cpp
folly/test/LifoSemTests.cpp
folly/test/LoggingTest.cpp
folly/test/MPMCQueueTest.cpp
folly/test/PaddedTest.cpp
folly/test/RangeFindBenchmark.cpp
folly/test/RangeTest.cpp
folly/test/SmallLocksTest.cpp
folly/test/StringTest.cpp
folly/test/SubprocessTest.cpp
folly/test/UriTest.cpp
folly/test/VarintTest.cpp
folly/test/function_benchmark/main.cpp
folly/test/small_vector_test.cpp

index 04411f633707ac9906f980c3d92b179a57dce800..e8a7f0a61fa19f16344116e6c1e93e7faa6f307e 100644 (file)
@@ -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;
 }
 
index 1bf3a3005d43084ead1912562944511475346e02..45e9e3a1ceea957668db595fbc6fdd17450ef3a6 100644 (file)
@@ -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;
index f18d6f33a78f26bcc405c28b32c5d24f652e04dc..533ac407a801dc06ea493b1bdfb64b8377d8c7bb 100644 (file)
@@ -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 {
index b457391746de64cf0ef90b93cd73f90b7a31b8d4..ce50ae1af55d9fa58c44e267309e4452b5d42eed 100644 (file)
@@ -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));
index c17e8849e8f080a2a722b84a35b5317a6a68b2df..11bbc3f7bd6e62fca06ece47ac9b4df570424d44 100644 (file)
@@ -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;
index 7ce9d301b25abb2b13030b0067aa8c9e50b641b8..2f8739fe138d71ecac06932d502224adc0f913b2 100644 (file)
@@ -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;
index e7d992aedab741a82b479c7289056a45d2e5b226..7af5962fb575c44892fa571787cc466a09a90158 100644 (file)
@@ -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;
   }
 
index 81030dbfd853940c1b20eded0e1f436e4270d71a..c4e3b8503d4b6c144fa86785f8a7ae345e13a774 100644 (file)
@@ -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;
 
index c21691f6f68809a0afdb72740d63e1f5dda2dcf9..721e56007ad4a0598731583117ecc420883f4ccf 100644 (file)
@@ -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]);
   }
 }
index 952c7f3392c553a18684bb6b580eb4cbf2501e80..2a98872e32ea3551dd2a073d887747f66c92fc8b 100644 (file)
@@ -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");
     }
index 863ccf5edc03e06ec392c174864a52d46f383d72..ee8c27e7c669807c7cb285870ff95eb23e2ff16c 100644 (file)
@@ -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) {
index 3a42202f815cf38a85a398d06d39f738a4b94ff2..821a41cb7e8cf13e555381869946907dc36f6752 100644 (file)
@@ -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));
   }
 }
index 715bd3722cbe10fa25831f1bd14344dc539d8c35..4ef2045451ba7ebf98065693623394c8844c2585 100644 (file)
@@ -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());
   }
 }
index db8ffdca8402ac37da9e5d07eb30723f7f589dc8..dfca621658e937e3eb36e9e50cf0e8f526df3426 100644 (file)
@@ -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;
index 5924f736051b70ab4ccc815fd0101281970495fe..18d8c2756610a6e710e8646ae89756213971d885 100644 (file)
@@ -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);
index ac10fd1809a9546b0aa282f3dc074d3ee94c96e9..243edc068a2774217de36046437a4984998a864c 100644 (file)
@@ -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);
     });
index a0b466c2fe83294d42b2572d08a811eb32691ab4..6bd2a2c0b2cd41ce825a4ba8b02cfd166dded7e9 100644 (file)
@@ -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(); }
index d6bb7122e6aec85fd463d9ad54ab3b2b013e7d07..3f28aa9a7d17af34052286e1cb557fa7d69e8bd0 100644 (file)
@@ -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]);
   }
 
index f52d2e78739ab0a47ac54be35e42286e8b28dc65..8c8fe61f11fdcf7ce5e01ff9a3104c74d765eae2 100644 (file)
@@ -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));
   }
index 2ee9319dc3b78dabc413f46d54f0098d8bbb84bd..9bee20982662ca8becd6160b8ba42c8f26caa1ea 100644 (file)
@@ -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");
index 6aab5321798f27386b8f3b5cf15a624fd95fb707..7f3ed6efd4bae3a89774b5ed8ce0d56309652bcb 100644 (file)
@@ -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 {
index 52125c258e4cc2834975f8a66ed8415482523207..95c27d36420e857205d0910642d0176ba9a12d27 100644 (file)
@@ -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;
   }
index 69cfe867363373f7310f83321bf1ec4520e4c985..ceba521110dc6d8f9f3fcc45daec5a6415b43b2f 100644 (file)
@@ -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) {
index e1051a1e88177c93ae3999606943b7921f3bdfae..9e7c5a44fe2ad6641938e3ccb79b8fc648693178 100644 (file)
@@ -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());
index a9d0624483423dbcf7108c10388c0be815c6556b..2b3a77d09cbc2ae3f1d8ef92273f88d7536c8d98 100644 (file)
@@ -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));
     }
index a91f571fe980a94e6a44752e2aa0c2406bcc74f8..9d57d62100c633d727570b9f6aa456ba392668f7 100644 (file)
@@ -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));
   }
index 8779a4c334ce536c8dc125a91d51bbf79740577d..f663bf253af164913b6f7e3da8f28ea3f48f73d9 100644 (file)
@@ -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);
   }
index 951079b5120afcd7c39f92eef37c0d8994a59278..daaa3f7e4e600e756b64766ddb3300170a1a9116 100644 (file)
@@ -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();
     }
index f0139648e734328933d58400b5a9fd699e9ea50b..d41dbbc8534e991e83553b9102eea3fd0336a9ad 100644 (file)
@@ -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();
   }
 
index d15b638da82ced1f1b2bc70c7f8177357e929cf5..31cd9edad5cffe0b05a9428001815f8ebbfbed8e 100644 (file)
@@ -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);
   }
index a079917e2ef0ed95b7b22776d118ae56ecf005e0..a0ab43800b8c51a454f6ac39379d59be7d55075d 100644 (file)
@@ -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
index e384be65947b03d04cddd8c4feefe31ef6175aac..c1062526c3cbd7a22f45343b0d38725c8888ff95 100644 (file)
@@ -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>());
         }
index b59bb0861ab0ecb20516ad78f5c285d82fe7c718..0b23fb21959988428d26617c89c07f04b63c1b93 100644 (file)
  * 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) {
index 698320c0a8a1794f5beeb553af5f6cd26ae8b36b..3b5ca72f1f8bef79ead69685618d99c45549325f 100644 (file)
@@ -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));
     }
   }
index a4fac00c928c5edf766159f5f79c9cf027854dab..bff6b502452ea61ca0776774d0ed887431b1b1ec 100644 (file)
@@ -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);
index 4b655027709d671bb34528eb8f8476ebe1aafddc..202661a6d6ea558d72f2231bdadb3718b088046f 100644 (file)
@@ -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) :
index 606e79a3ddae4b1bf004e8980dca1e301423fb9e..334164fa92d823fb2cce4f187fc36555af600abf 100644 (file)
@@ -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);
   }
 }
index 7d034211827ae7065965f987b1d56c1cebeb5952..f561d2a5a061282afac1731c11e8c32d6200196a 100644 (file)
@@ -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);
index 11269253a4bcf60a2573733b9aeb3765ea3fa3ab..d404bd34816ec178156625e82c8054617c58c1cd 100644 (file)
@@ -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)) {
index be1fbc904d6b3837e7ec689b7eb1f6d03aa7cfb6..50dcafef2fdb1530589dcd53345ceddcd0970edb 100644 (file)
@@ -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));
index 324a91d4742101f2d56008c551facc0176bc536e..bed71c9838b9e961a41de088c53c78903c1b4178 100644 (file)
@@ -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;
index eecbf9c35b6823e3e492a08a5ca75e5d02340026..306aa7abc5f4fbbf76d6bcc1ed8be200b2967763 100644 (file)
@@ -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);
index afc8ec8a8fa4cd130cc1d03f181a34d3db988de5..a8f2c615f67e5153959009ab26f7cb56419de4c0 100644 (file)
@@ -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);
index f0fd291d1da13e7c99b2adb022997200e3647b5d..bafb68321b8db2ba1c87f567250155c1ff48e56e 100644 (file)
@@ -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]);
     }
 
index e24f30285302dd9dc7735d4afac3bce8c8c75209..23ee318a173e790604702b04f2fd80b2dc2e3479 100644 (file)
@@ -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);
   }
index a2ffc8dc860aaef83aa04c3032989b726837bfd3..283928de7b42b49d78b0d46fd3068ba3ded0109d 100644 (file)
@@ -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());
     }
 
index d16242d60f373af3d0c84e1ff018b036964aa867..9796720315734a424a405d9592a0b06b2b35d151 100644 (file)
@@ -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();
   }
index 91da0536626252b89f3bd968b7242693b086092d..546ebc3e5e648843b4f63b27d9cbeca5e4d1d9e3 100644 (file)
@@ -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;
index 13d8a67fe5d74f37e38bbcaf8b7e8c3685bab4e7..e58047dc5b34ec56f513450aad4c3817ce2a3b66 100644 (file)
@@ -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);
   }
 }
index f80a4605dfc67b4156d3fdb9485314b4fe78a8bd..0e014a2c2aef4930a3d9ed1cb30a4d8acac60a69 100644 (file)
@@ -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);
   }