Make most implicit integer truncations and sign conversions explicit
[folly.git] / folly / AtomicUnorderedMap.h
index 34cdf8598a0d7b35214623e649f873fbd231d61f..12c02579d6b2f81fd25bbdaaa6150620b5fbaca0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@
 #include <system_error>
 #include <type_traits>
 #include <stdint.h>
-#include <unistd.h>
 
 #include <folly/Bits.h>
 #include <folly/Conv.h>
@@ -30,6 +29,7 @@
 #include <folly/Random.h>
 #include <folly/detail/AtomicUnorderedMapUtils.h>
 #include <folly/portability/SysMman.h>
+#include <folly/portability/Unistd.h>
 
 #include <boost/type_traits/has_trivial_destructor.hpp>
 #include <limits>
@@ -212,7 +212,7 @@ struct AtomicUnorderedInsertMap {
       const Allocator& alloc = Allocator())
     : allocator_(alloc)
   {
-    size_t capacity = maxSize / std::min(1.0f, maxLoadFactor) + 128;
+    size_t capacity = size_t(maxSize / std::min(1.0f, maxLoadFactor) + 128);
     size_t avail = size_t{1} << (8 * sizeof(IndexType) - 2);
     if (capacity > avail && maxSize < avail) {
       // we'll do our best
@@ -454,13 +454,13 @@ struct AtomicUnorderedInsertMap {
   /// can specialize it differently during deterministic testing
   IndexType allocationAttempt(IndexType start, IndexType tries) const {
     if (LIKELY(tries < 8 && start + tries < numSlots_)) {
-      return start + tries;
+      return IndexType(start + tries);
     } else {
       IndexType rv;
       if (sizeof(IndexType) <= 4) {
-        rv = folly::Random::rand32(numSlots_);
+        rv = IndexType(folly::Random::rand32(numSlots_));
       } else {
-        rv = folly::Random::rand64(numSlots_);
+        rv = IndexType(folly::Random::rand64(numSlots_));
       }
       assert(rv < numSlots_);
       return rv;