core-local array type conversions
authorAndrew Kryczka <andrewkr@fb.com>
Fri, 12 May 2017 16:26:40 +0000 (09:26 -0700)
committerGaudenz Steinlin <gaudenz@debian.org>
Sat, 29 Dec 2018 21:08:52 +0000 (21:08 +0000)
Summary:
try to clean up the type conversions and hope it passes on windows.

one interesting thing I learned is that bitshift operations are special: in `x << y`, the result type depends only on the type of `x`, unlike most arithmetic operations where the result type depends on both operands' types.
Closes https://github.com/facebook/rocksdb/pull/2277

Differential Revision: D5050145

Pulled By: ajkr

fbshipit-source-id: f3309e77526ac9612c632bf93a62d99757af9a29
(cherry picked from commit bbe9ee7dd4a542b191ace521ca13b4bdb063008b)

Gbp-Pq: Name 0002-core-local-array-type-conversions.patch

src/rocksdb/util/core_local.h

index 806584d46cee79c54d1d066c00275300fdbc5331..7515c542362e95078cb9efdab0ecb809be05a673 100644 (file)
@@ -38,23 +38,23 @@ class CoreLocalArray {
 
  private:
   std::unique_ptr<T[]> data_;
-  size_t size_shift_;
+  int size_shift_;
 };
 
 template<typename T>
 CoreLocalArray<T>::CoreLocalArray() {
-  unsigned int num_cpus = std::thread::hardware_concurrency();
+  int num_cpus = static_cast<int>(std::thread::hardware_concurrency());
   // find a power of two >= num_cpus and >= 8
   size_shift_ = 3;
-  while (1u << size_shift_ < num_cpus) {
+  while (1 << size_shift_ < num_cpus) {
     ++size_shift_;
   }
-  data_.reset(new T[1 << size_shift_]);
+  data_.reset(new T[static_cast<size_t>(1) << size_shift_]);
 }
 
 template<typename T>
 size_t CoreLocalArray<T>::Size() const {
-  return 1u << size_shift_;
+  return static_cast<size_t>(1) << size_shift_;
 }
 
 template<typename T>
@@ -77,7 +77,7 @@ std::pair<T*, size_t> CoreLocalArray<T>::AccessElementAndIndex() const {
 
 template<typename T>
 T* CoreLocalArray<T>::AccessAtCore(size_t core_idx) const {
-  assert(core_idx < 1u << size_shift_);
+  assert(core_idx < static_cast<size_t>(1) << size_shift_);
   return &data_[core_idx];
 }