diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-09-14 15:41:19 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-09-14 15:41:19 +0300 |
commit | a98760f7dad7948fc50613d2c39cb9cbe8a4fb08 (patch) | |
tree | 353411faffa99519c661e8bdfc84e1896a541f07 /source/blender/blenlib | |
parent | 5b00ecf70bf6876d1279e8e8f73a5d722f77cb51 (diff) |
BLI: speedup adding to VectorSet by removing a check
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_vector.h | 13 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_vector_set.h | 14 |
2 files changed, 17 insertions, 10 deletions
diff --git a/source/blender/blenlib/BLI_vector.h b/source/blender/blenlib/BLI_vector.h index c9701dcaa52..7a001c653d2 100644 --- a/source/blender/blenlib/BLI_vector.h +++ b/source/blender/blenlib/BLI_vector.h @@ -512,6 +512,14 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve return m_end; } + /** + * Get the current capacity of the vector. + */ + uint capacity() const + { + return (uint)(m_capacity_end - m_begin); + } + void print_stats() const { std::cout << "Small Vector at " << (void *)this << ":" << std::endl; @@ -538,11 +546,6 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve } } - uint capacity() const - { - return (uint)(m_capacity_end - m_begin); - } - BLI_NOINLINE void grow(uint min_capacity) { if (this->capacity() >= min_capacity) { diff --git a/source/blender/blenlib/BLI_vector_set.h b/source/blender/blenlib/BLI_vector_set.h index c61643fa3d8..5de3ae298a7 100644 --- a/source/blender/blenlib/BLI_vector_set.h +++ b/source/blender/blenlib/BLI_vector_set.h @@ -115,19 +115,22 @@ template<typename T, typename Allocator = GuardedAllocator> class VectorSet { Vector<T, 4, Allocator> m_elements; public: - VectorSet() = default; + VectorSet() + { + BLI_assert(m_array.slots_usable() <= m_elements.capacity()); + } - VectorSet(ArrayRef<T> values) + VectorSet(ArrayRef<T> values) : VectorSet() { this->add_multiple(values); } - VectorSet(const std::initializer_list<T> &values) + VectorSet(const std::initializer_list<T> &values) : VectorSet() { this->add_multiple(values); } - VectorSet(const Vector<T> &values) + VectorSet(const Vector<T> &values) : VectorSet() { this->add_multiple(values); } @@ -316,7 +319,7 @@ template<typename T, typename Allocator = GuardedAllocator> class VectorSet { { uint index = m_elements.size(); slot.set_index(index); - m_elements.append(std::forward<ForwardT>(value)); + m_elements.append_unchecked(std::forward<ForwardT>(value)); m_array.update__empty_to_set(); } @@ -336,6 +339,7 @@ template<typename T, typename Allocator = GuardedAllocator> class VectorSet { } m_array = std::move(new_array); + m_elements.reserve(m_array.slots_usable()); } void add_after_grow(uint index, ArrayType &new_array) |