From 5d79f9f276b4b3e6289308c534c58e7ee3bb5e2d Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Sun, 5 Jul 2020 16:30:26 +0200 Subject: BLI: refactor how buffers for small object optimization are stored --- source/blender/blenlib/BLI_vector.hh | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'source/blender/blenlib/BLI_vector.hh') diff --git a/source/blender/blenlib/BLI_vector.hh b/source/blender/blenlib/BLI_vector.hh index a06be65685f..e4f5afe661d 100644 --- a/source/blender/blenlib/BLI_vector.hh +++ b/source/blender/blenlib/BLI_vector.hh @@ -92,7 +92,7 @@ class Vector { Allocator allocator_; /** A placeholder buffer that will remain uninitialized until it is used. */ - AlignedBuffer<(uint)sizeof(T) * InlineBufferCapacity, (uint)alignof(T)> inline_buffer_; + TypedBuffer inline_buffer_; /** * Store the size of the vector explicitly in debug builds. Otherwise you'd always have to call @@ -120,7 +120,7 @@ class Vector { */ Vector() { - begin_ = this->inline_buffer(); + begin_ = inline_buffer_; end_ = begin_; capacity_end_ = begin_ + InlineBufferCapacity; UPDATE_VECTOR_SIZE(this); @@ -227,7 +227,7 @@ class Vector { if (other.is_inline()) { if (size <= InlineBufferCapacity) { /* Copy between inline buffers. */ - begin_ = this->inline_buffer(); + begin_ = inline_buffer_; end_ = begin_ + size; capacity_end_ = begin_ + InlineBufferCapacity; uninitialized_relocate_n(other.begin_, size, begin_); @@ -248,7 +248,7 @@ class Vector { capacity_end_ = other.capacity_end_; } - other.begin_ = other.inline_buffer(); + other.begin_ = other.inline_buffer_; other.end_ = other.begin_; other.capacity_end_ = other.begin_ + OtherInlineBufferCapacity; UPDATE_VECTOR_SIZE(this); @@ -399,7 +399,7 @@ class Vector { allocator_.deallocate(begin_); } - begin_ = this->inline_buffer(); + begin_ = inline_buffer_; end_ = begin_; capacity_end_ = begin_ + InlineBufferCapacity; UPDATE_VECTOR_SIZE(this); @@ -763,14 +763,9 @@ class Vector { } private: - T *inline_buffer() const - { - return (T *)inline_buffer_.ptr(); - } - bool is_inline() const { - return begin_ == this->inline_buffer(); + return begin_ == inline_buffer_; } void ensure_space_for_one() @@ -817,7 +812,7 @@ class Vector { uint capacity; if (size <= InlineBufferCapacity) { - begin_ = this->inline_buffer(); + begin_ = inline_buffer_; capacity = InlineBufferCapacity; } else { -- cgit v1.2.3