diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_array.hh | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_hash.hh | 12 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_linear_allocator.hh | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_map.hh | 6 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_map_slots.hh | 26 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_memory_utils.hh | 15 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_optional.hh | 8 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_set.hh | 4 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_set_slots.hh | 16 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_stack.hh | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_string_ref.hh | 6 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_vector.hh | 6 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_vector_set.hh | 2 |
13 files changed, 59 insertions, 48 deletions
diff --git a/source/blender/blenlib/BLI_array.hh b/source/blender/blenlib/BLI_array.hh index b929d1220da..07155439170 100644 --- a/source/blender/blenlib/BLI_array.hh +++ b/source/blender/blenlib/BLI_array.hh @@ -55,7 +55,7 @@ template< * The number of values that can be stored in the array, without doing a heap allocation. * * When T is large, the small buffer optimization is disabled by default to avoid large - * unexpected allocations on the stack. It can still be enabled explicitely though. + * unexpected allocations on the stack. It can still be enabled explicitly though. */ uint InlineBufferCapacity = (sizeof(T) < 100) ? 4 : 0, /** diff --git a/source/blender/blenlib/BLI_hash.hh b/source/blender/blenlib/BLI_hash.hh index 57d5f7f9d8a..5490c953756 100644 --- a/source/blender/blenlib/BLI_hash.hh +++ b/source/blender/blenlib/BLI_hash.hh @@ -65,7 +65,7 @@ * * - When you want to provide a different hash function for a type that already has a default hash * function: Implement a struct like the one below and pass it as template parameter to the hash - * table explicitely. + * table explicitly. * * struct MyCustomHash { * uint32_t operator()(const TheType &value) const { @@ -97,6 +97,16 @@ template<typename T> struct DefaultHash { } }; +/** + * Use the same hash function for const and non const variants of a type. + */ +template<typename T> struct DefaultHash<const T> { + uint32_t operator()(const T &value) const + { + return DefaultHash<T>{}(value); + } +}; + #define TRIVIAL_DEFAULT_INT_HASH(TYPE) \ template<> struct DefaultHash<TYPE> { \ uint32_t operator()(TYPE value) const \ diff --git a/source/blender/blenlib/BLI_linear_allocator.hh b/source/blender/blenlib/BLI_linear_allocator.hh index f968f9f15ce..2a0dc939cb9 100644 --- a/source/blender/blenlib/BLI_linear_allocator.hh +++ b/source/blender/blenlib/BLI_linear_allocator.hh @@ -171,7 +171,7 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya MutableSpan<T *> pointers = void_pointers.cast<T *>(); for (uint i : IndexRange(n)) { - new (pointers[i]) T(std::forward<Args>(args)...); + new ((void *)pointers[i]) T(std::forward<Args>(args)...); } return pointers; diff --git a/source/blender/blenlib/BLI_map.hh b/source/blender/blenlib/BLI_map.hh index 4fc9f98d835..a4c3ee76ca1 100644 --- a/source/blender/blenlib/BLI_map.hh +++ b/source/blender/blenlib/BLI_map.hh @@ -94,7 +94,7 @@ template< * that (unlike vector) initializing a map has a O(n) cost in the number of slots. * * When Key or Value are large, the small buffer optimization is disabled by default to avoid - * large unexpected allocations on the stack. It can still be enabled explicitely though. + * large unexpected allocations on the stack. It can still be enabled explicitly though. */ uint32_t InlineBufferCapacity = (sizeof(Key) + sizeof(Value) < 100) ? 4 : 0, /** @@ -470,7 +470,7 @@ class Map { const ModifyValueF &modify_value) -> decltype(create_value(nullptr)) { return this->add_or_modify__impl( - std::forward<Key>(key), create_value, modify_value, m_hash(key)); + std::forward<ForwardKey>(key), create_value, modify_value, m_hash(key)); } /** @@ -1175,7 +1175,7 @@ class Map { bool add_overwrite__impl(ForwardKey &&key, ForwardValue &&value, uint32_t hash) { auto create_func = [&](Value *ptr) { - new (ptr) Value(std::forward<ForwardValue>(value)); + new ((void *)ptr) Value(std::forward<ForwardValue>(value)); return true; }; auto modify_func = [&](Value *ptr) { diff --git a/source/blender/blenlib/BLI_map_slots.hh b/source/blender/blenlib/BLI_map_slots.hh index 9ea2c4cad89..f12eefcaf0b 100644 --- a/source/blender/blenlib/BLI_map_slots.hh +++ b/source/blender/blenlib/BLI_map_slots.hh @@ -84,13 +84,13 @@ template<typename Key, typename Value> class SimpleMapSlot { { m_state = other.m_state; if (other.m_state == Occupied) { - new (this->key()) Key(*other.key()); - new (this->value()) Value(*other.value()); + new ((void *)this->key()) Key(*other.key()); + new ((void *)this->value()) Value(*other.value()); } } /** - * The move construtor has to copy the state. If the other slot was occupied, the key and value + * The move constructor has to copy the state. If the other slot was occupied, the key and value * from the other have to moved as well. The other slot stays in the state it was in before. Its * optionally stored key and value remain in a moved-from state. */ @@ -98,8 +98,8 @@ template<typename Key, typename Value> class SimpleMapSlot { { m_state = other.m_state; if (other.m_state == Occupied) { - new (this->key()) Key(std::move(*other.key())); - new (this->value()) Value(std::move(*other.value())); + new ((void *)this->key()) Key(std::move(*other.key())); + new ((void *)this->value()) Value(std::move(*other.value())); } } @@ -170,8 +170,8 @@ template<typename Key, typename Value> class SimpleMapSlot { BLI_assert(!this->is_occupied()); BLI_assert(other.is_occupied()); m_state = Occupied; - new (this->key()) Key(std::move(*other.key())); - new (this->value()) Value(std::move(*other.value())); + new ((void *)this->key()) Key(std::move(*other.key())); + new ((void *)this->value()) Value(std::move(*other.value())); other.key()->~Key(); other.value()->~Value(); } @@ -198,7 +198,7 @@ template<typename Key, typename Value> class SimpleMapSlot { { BLI_assert(!this->is_occupied()); this->occupy_without_value(std::forward<ForwardKey>(key), hash); - new (this->value()) Value(std::forward<ForwardValue>(value)); + new ((void *)this->value()) Value(std::forward<ForwardValue>(value)); } /** @@ -209,7 +209,7 @@ template<typename Key, typename Value> class SimpleMapSlot { { BLI_assert(!this->is_occupied()); m_state = Occupied; - new (this->key()) Key(std::forward<ForwardKey>(key)); + new ((void *)this->key()) Key(std::forward<ForwardKey>(key)); } /** @@ -251,14 +251,14 @@ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot IntrusiveMapSlot(const IntrusiveMapSlot &other) : m_key(other.m_key) { if (KeyInfo::is_not_empty_or_removed(m_key)) { - new (this->value()) Value(*other.value()); + new ((void *)this->value()) Value(*other.value()); } } IntrusiveMapSlot(IntrusiveMapSlot &&other) noexcept : m_key(other.m_key) { if (KeyInfo::is_not_empty_or_removed(m_key)) { - new (this->value()) Value(std::move(*other.value())); + new ((void *)this->value()) Value(std::move(*other.value())); } } @@ -303,7 +303,7 @@ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot BLI_assert(!this->is_occupied()); BLI_assert(other.is_occupied()); m_key = std::move(other.m_key); - new (this->value()) Value(std::move(*other.value())); + new ((void *)this->value()) Value(std::move(*other.value())); other.m_key.~Key(); other.value()->~Value(); } @@ -321,7 +321,7 @@ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot BLI_assert(!this->is_occupied()); BLI_assert(KeyInfo::is_not_empty_or_removed(key)); this->occupy_without_value(std::forward<ForwardKey>(key), hash); - new (this->value()) Value(std::forward<ForwardValue>(value)); + new ((void *)this->value()) Value(std::forward<ForwardValue>(value)); } template<typename ForwardKey> void occupy_without_value(ForwardKey &&key, uint32_t UNUSED(hash)) diff --git a/source/blender/blenlib/BLI_memory_utils.hh b/source/blender/blenlib/BLI_memory_utils.hh index de9fc956bfb..81792e2101c 100644 --- a/source/blender/blenlib/BLI_memory_utils.hh +++ b/source/blender/blenlib/BLI_memory_utils.hh @@ -22,6 +22,7 @@ */ #include <memory> +#include <new> #include "BLI_utildefines.h" @@ -39,13 +40,13 @@ namespace blender { template<typename T> void default_construct_n(T *ptr, uint n) { /* This is not strictly necessary, because the loop below will be optimized away anyway. It is - * nice to make behavior this explicitely, though. */ + * nice to make behavior this explicitly, though. */ if (std::is_trivially_constructible<T>::value) { return; } for (uint i = 0; i < n; i++) { - new (ptr + i) T; + new ((void *)(ptr + i)) T; } } @@ -61,7 +62,7 @@ template<typename T> void default_construct_n(T *ptr, uint n) template<typename T> void destruct_n(T *ptr, uint n) { /* This is not strictly necessary, because the loop below will be optimized away anyway. It is - * nice to make behavior this explicitely, though. */ + * nice to make behavior this explicitly, though. */ if (std::is_trivially_destructible<T>::value) { return; } @@ -101,7 +102,7 @@ template<typename T> void initialized_copy_n(const T *src, uint n, T *dst) template<typename T> void uninitialized_copy_n(const T *src, uint n, T *dst) { for (uint i = 0; i < n; i++) { - new (dst + i) T(src[i]); + new ((void *)(dst + i)) T(src[i]); } } @@ -135,7 +136,7 @@ template<typename T> void initialized_move_n(T *src, uint n, T *dst) template<typename T> void uninitialized_move_n(T *src, uint n, T *dst) { for (uint i = 0; i < n; i++) { - new (dst + i) T(std::move(src[i])); + new ((void *)(dst + i)) T(std::move(src[i])); } } @@ -162,7 +163,7 @@ template<typename T> void initialized_relocate_n(T *src, uint n, T *dst) * * Before: * src: initialized - * dst: uinitialized + * dst: uninitialized * After: * src: uninitialized * dst: initialized @@ -199,7 +200,7 @@ template<typename T> void initialized_fill_n(T *dst, uint n, const T &value) template<typename T> void uninitialized_fill_n(T *dst, uint n, const T &value) { for (uint i = 0; i < n; i++) { - new (dst + i) T(value); + new ((void *)(dst + i)) T(value); } } diff --git a/source/blender/blenlib/BLI_optional.hh b/source/blender/blenlib/BLI_optional.hh index b5f98d6fa97..2e6b66d0eac 100644 --- a/source/blender/blenlib/BLI_optional.hh +++ b/source/blender/blenlib/BLI_optional.hh @@ -121,7 +121,7 @@ template<typename T> class Optional { this->value() = value; } else { - new (this->value_ptr()) T(value); + new ((void *)this->value_ptr()) T(value); m_set = true; } } @@ -132,7 +132,7 @@ template<typename T> class Optional { this->value() = std::move(value); } else { - new (this->value_ptr()) T(std::move(value)); + new ((void *)this->value_ptr()) T(std::move(value)); m_set = true; } } @@ -140,14 +140,14 @@ template<typename T> class Optional { void set_new(const T &value) { BLI_assert(!m_set); - new (this->value_ptr()) T(value); + new ((void *)this->value_ptr()) T(value); m_set = true; } void set_new(T &&value) { BLI_assert(!m_set); - new (this->value_ptr()) T(std::move(value)); + new ((void *)this->value_ptr()) T(std::move(value)); m_set = true; } diff --git a/source/blender/blenlib/BLI_set.hh b/source/blender/blenlib/BLI_set.hh index af0c3424f5a..d23aa96e434 100644 --- a/source/blender/blenlib/BLI_set.hh +++ b/source/blender/blenlib/BLI_set.hh @@ -91,7 +91,7 @@ template< * that (unlike vector) initializing a set has a O(n) cost in the number of slots. * * When Key is large, the small buffer optimization is disabled by default to avoid large - * unexpected allocations on the stack. It can still be enabled explicitely though. + * unexpected allocations on the stack. It can still be enabled explicitly though. */ uint32_t InlineBufferCapacity = (sizeof(Key) < 100) ? 4 : 0, /** @@ -433,7 +433,7 @@ class Set { /** * Creates a new slot array and reinserts all keys inside of that. This method can be used to get - * rid of dummy slots. Also this is useful for benchmarking the grow function. + * rid of removed slots. Also this is useful for benchmarking the grow function. */ void rehash() { diff --git a/source/blender/blenlib/BLI_set_slots.hh b/source/blender/blenlib/BLI_set_slots.hh index 15f56f2450e..581e70ce628 100644 --- a/source/blender/blenlib/BLI_set_slots.hh +++ b/source/blender/blenlib/BLI_set_slots.hh @@ -80,7 +80,7 @@ template<typename Key> class SimpleSetSlot { { m_state = other.m_state; if (other.m_state == Occupied) { - new (this->key()) Key(*other.key()); + new ((void *)this->key()) Key(*other.key()); } } @@ -93,7 +93,7 @@ template<typename Key> class SimpleSetSlot { { m_state = other.m_state; if (other.m_state == Occupied) { - new (this->key()) Key(std::move(*other.key())); + new ((void *)this->key()) Key(std::move(*other.key())); } } @@ -148,7 +148,7 @@ template<typename Key> class SimpleSetSlot { BLI_assert(!this->is_occupied()); BLI_assert(other.is_occupied()); m_state = Occupied; - new (this->key()) Key(std::move(*other.key())); + new ((void *)this->key()) Key(std::move(*other.key())); other.key()->~Key(); } @@ -173,7 +173,7 @@ template<typename Key> class SimpleSetSlot { { BLI_assert(!this->is_occupied()); m_state = Occupied; - new (this->key()) Key(std::forward<ForwardKey>(key)); + new ((void *)this->key()) Key(std::forward<ForwardKey>(key)); } /** @@ -221,7 +221,7 @@ template<typename Key> class HashedSetSlot { m_state = other.m_state; if (other.m_state == Occupied) { m_hash = other.m_hash; - new (this->key()) Key(*other.key()); + new ((void *)this->key()) Key(*other.key()); } } @@ -230,7 +230,7 @@ template<typename Key> class HashedSetSlot { m_state = other.m_state; if (other.m_state == Occupied) { m_hash = other.m_hash; - new (this->key()) Key(std::move(*other.key())); + new ((void *)this->key()) Key(std::move(*other.key())); } } @@ -266,7 +266,7 @@ template<typename Key> class HashedSetSlot { BLI_assert(other.is_occupied()); m_state = Occupied; m_hash = hash; - new (this->key()) Key(std::move(*other.key())); + new ((void *)this->key()) Key(std::move(*other.key())); other.key()->~Key(); } @@ -287,7 +287,7 @@ template<typename Key> class HashedSetSlot { BLI_assert(!this->is_occupied()); m_state = Occupied; m_hash = hash; - new (this->key()) Key(std::forward<ForwardKey>(key)); + new ((void *)this->key()) Key(std::forward<ForwardKey>(key)); } void remove() diff --git a/source/blender/blenlib/BLI_stack.hh b/source/blender/blenlib/BLI_stack.hh index 030d9c84c8e..2170b8b23bc 100644 --- a/source/blender/blenlib/BLI_stack.hh +++ b/source/blender/blenlib/BLI_stack.hh @@ -75,7 +75,7 @@ template< * not initialized when it is not needed. * * When T is large, the small buffer optimization is disabled by default to avoid large - * unexpected allocations on the stack. It can still be enabled explicitely though. + * unexpected allocations on the stack. It can still be enabled explicitly though. */ uint InlineBufferCapacity = (sizeof(T) < 100) ? 4 : 0, /** diff --git a/source/blender/blenlib/BLI_string_ref.hh b/source/blender/blenlib/BLI_string_ref.hh index 073137fe175..bb8479efe95 100644 --- a/source/blender/blenlib/BLI_string_ref.hh +++ b/source/blender/blenlib/BLI_string_ref.hh @@ -292,8 +292,8 @@ inline std::ostream &operator<<(std::ostream &stream, StringRefNull ref) } /** - * Adding two StringRefs will allocate an std::string. This is not efficient, but convenient in - * most cases. + * Adding two #StringRefs will allocate an std::string. + * This is not efficient, but convenient in most cases. */ inline std::string operator+(StringRef a, StringRef b) { @@ -347,7 +347,7 @@ inline bool StringRefBase::endswith(StringRef suffix) const } /** - * Return a new StringRef containing only a substring of the original string. + * Return a new #StringRef containing only a sub-string of the original string. */ inline StringRef StringRefBase::substr(uint start, uint size) const { diff --git a/source/blender/blenlib/BLI_vector.hh b/source/blender/blenlib/BLI_vector.hh index b2b2da0a4b0..f61a3d4282b 100644 --- a/source/blender/blenlib/BLI_vector.hh +++ b/source/blender/blenlib/BLI_vector.hh @@ -68,7 +68,7 @@ template< * not initialized when it is not needed. * * When T is large, the small buffer optimization is disabled by default to avoid large - * unexpected allocations on the stack. It can still be enabled explicitely though. + * unexpected allocations on the stack. It can still be enabled explicitly though. */ uint InlineBufferCapacity = (sizeof(T) < 100) ? 4 : 0, /** @@ -79,7 +79,7 @@ template< class Vector { private: /** - * Use pointers instead of storing the size explicitely. This reduces the number of instructions + * Use pointers instead of storing the size explicitly. This reduces the number of instructions * in `append`. * * The pointers might point to the memory in the inline buffer. @@ -95,7 +95,7 @@ class Vector { AlignedBuffer<(uint)sizeof(T) * InlineBufferCapacity, (uint)alignof(T)> m_inline_buffer; /** - * Store the size of the vector explicitely in debug builds. Otherwise you'd always have to call + * Store the size of the vector explicitly in debug builds. Otherwise you'd always have to call * the `size` function or do the math to compute it from the pointers manually. This is rather * annoying. Knowing the size of a vector is often quite essential when debugging some code. */ diff --git a/source/blender/blenlib/BLI_vector_set.hh b/source/blender/blenlib/BLI_vector_set.hh index dcd4927aed2..03f25a68cd8 100644 --- a/source/blender/blenlib/BLI_vector_set.hh +++ b/source/blender/blenlib/BLI_vector_set.hh @@ -27,7 +27,7 @@ * * All core operations (add, remove and contains) can be done in O(1) amortized expected time. * - * Using a VectorSet instead of a normal Set can be benefitial in any of the following + * Using a VectorSet instead of a normal Set can be beneficial in any of the following * circumstances: * - The insertion order is important. * - Iteration over all keys has to be fast. |