From bbe9ee7dd4a542b191ace521ca13b4bdb063008b Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Fri, 12 May 2017 09:26:40 -0700 Subject: [PATCH] core-local array type conversions 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 --- util/core_local.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/util/core_local.h b/util/core_local.h index 806584d46..7515c5423 100644 --- a/util/core_local.h +++ b/util/core_local.h @@ -38,23 +38,23 @@ class CoreLocalArray { private: std::unique_ptr data_; - size_t size_shift_; + int size_shift_; }; template CoreLocalArray::CoreLocalArray() { - unsigned int num_cpus = std::thread::hardware_concurrency(); + int num_cpus = static_cast(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(1) << size_shift_]); } template size_t CoreLocalArray::Size() const { - return 1u << size_shift_; + return static_cast(1) << size_shift_; } template @@ -77,7 +77,7 @@ std::pair CoreLocalArray::AccessElementAndIndex() const { template T* CoreLocalArray::AccessAtCore(size_t core_idx) const { - assert(core_idx < 1u << size_shift_); + assert(core_idx < static_cast(1) << size_shift_); return &data_[core_idx]; }