diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-09-13 12:03:49 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-09-13 12:03:49 +0300 |
commit | bb7c858598ff263eb29f676ec8ef8b2f43b20c43 (patch) | |
tree | 4481ffc8fcd16548c8436883e54f10d8c41ffe46 /source | |
parent | 394318da74e5fddf14e19d7129a6d8406b67eb34 (diff) |
BLI: make more integer type conversions explicit
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_open_addressing.h | 10 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_set_vector.h | 4 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_vector.h | 10 |
3 files changed, 12 insertions, 12 deletions
diff --git a/source/blender/blenlib/BLI_open_addressing.h b/source/blender/blenlib/BLI_open_addressing.h index 3bdacae18d1..32e89c19139 100644 --- a/source/blender/blenlib/BLI_open_addressing.h +++ b/source/blender/blenlib/BLI_open_addressing.h @@ -42,7 +42,7 @@ namespace BLI { template<typename Item, uint32_t ItemsInSmallStorage = 1, typename Allocator = GuardedAllocator> class OpenAddressingArray { private: - static constexpr auto slots_per_item = Item::slots_per_item; + static constexpr uint32_t slots_per_item = Item::slots_per_item; static constexpr float max_load_factor = 0.5f; /* Invariants: @@ -74,10 +74,10 @@ class OpenAddressingArray { public: explicit OpenAddressingArray(uint8_t item_exponent = 0) { - m_slots_total = (1 << item_exponent) * slots_per_item; + m_slots_total = ((uint32_t)1 << item_exponent) * slots_per_item; m_slots_set_or_dummy = 0; m_slots_dummy = 0; - m_slots_usable = m_slots_total * max_load_factor; + m_slots_usable = (uint32_t)((float)m_slots_total * max_load_factor); m_slot_mask = m_slots_total - 1; m_item_amount = m_slots_total / slots_per_item; m_item_exponent = item_exponent; @@ -87,7 +87,7 @@ class OpenAddressingArray { } else { m_items = (Item *)m_allocator.allocate_aligned( - sizeof(Item) * m_item_amount, std::alignment_of<Item>::value, __func__); + (uint32_t)sizeof(Item) * m_item_amount, std::alignment_of<Item>::value, __func__); } for (uint32_t i = 0; i < m_item_amount; i++) { @@ -176,7 +176,7 @@ class OpenAddressingArray { { float min_total_slots = (float)min_usable_slots / max_load_factor; uint32_t min_total_items = (uint32_t)std::ceil(min_total_slots / (float)slots_per_item); - uint8_t item_exponent = log2_ceil_u(min_total_items); + uint8_t item_exponent = (uint8_t)log2_ceil_u(min_total_items); OpenAddressingArray grown(item_exponent); grown.m_slots_set_or_dummy = this->slots_set(); return grown; diff --git a/source/blender/blenlib/BLI_set_vector.h b/source/blender/blenlib/BLI_set_vector.h index 083e72f5a9b..92c660a88f2 100644 --- a/source/blender/blenlib/BLI_set_vector.h +++ b/source/blender/blenlib/BLI_set_vector.h @@ -88,7 +88,7 @@ template<typename T, typename Allocator = GuardedAllocator> class SetVector { uint index() const { BLI_assert(this->is_set()); - return m_value; + return (uint)m_value; } int32_t &index_ref() @@ -99,7 +99,7 @@ template<typename T, typename Allocator = GuardedAllocator> class SetVector { void set_index(uint index) { BLI_assert(!this->is_set()); - m_value = index; + m_value = (int32_t)index; } void set_dummy() diff --git a/source/blender/blenlib/BLI_vector.h b/source/blender/blenlib/BLI_vector.h index 167131cc99e..1901f2a60ad 100644 --- a/source/blender/blenlib/BLI_vector.h +++ b/source/blender/blenlib/BLI_vector.h @@ -52,7 +52,7 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve #ifdef DEBUG /* Storing size in debug builds, because it makes debugging much easier sometimes. */ uint m_debug_size; -# define UPDATE_VECTOR_SIZE(ptr) (ptr)->m_debug_size = (ptr)->m_end - (ptr)->m_begin +# define UPDATE_VECTOR_SIZE(ptr) (ptr)->m_debug_size = (uint)((ptr)->m_end - (ptr)->m_begin) #else # define UPDATE_VECTOR_SIZE(ptr) ((void)0) #endif @@ -387,8 +387,8 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve */ uint size() const { - BLI_assert(m_debug_size == m_end - m_begin); - return m_end - m_begin; + BLI_assert(m_debug_size == (uint)(m_end - m_begin)); + return (uint)(m_end - m_begin); } /** @@ -539,7 +539,7 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve uint capacity() const { - return m_capacity_end - m_begin; + return (uint)(m_capacity_end - m_begin); } BLI_NOINLINE void grow(uint min_capacity) @@ -554,7 +554,7 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve uint size = this->size(); T *new_array = (T *)m_allocator.allocate_aligned( - min_capacity * sizeof(T), std::alignment_of<T>::value, __func__); + min_capacity * (uint)sizeof(T), std::alignment_of<T>::value, __func__); uninitialized_relocate_n(m_begin, size, new_array); if (!this->is_small()) { |