diff options
author | Jacques Lucke <jacques@blender.org> | 2020-06-09 12:58:47 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-06-09 12:58:47 +0300 |
commit | f7c0f1b8b83ac475755b633abf59cf9f447b2d49 (patch) | |
tree | 97302f741ce4e40f6e4de9f0cfd54c7320ee7fd5 /source/blender/blenlib/BLI_linear_allocator.hh | |
parent | 7d2b4ae9c6ecce394130cd08694914bf93497a11 (diff) |
BLI: rename ArrayRef to Span
This also renames `MutableArrayRef` to `MutableSpan`.
The name "Span" works better, because `std::span` will provide
similar functionality in C++20. Furthermore, a shorter, more
concise name for a common data structure is nice.
Diffstat (limited to 'source/blender/blenlib/BLI_linear_allocator.hh')
-rw-r--r-- | source/blender/blenlib/BLI_linear_allocator.hh | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/source/blender/blenlib/BLI_linear_allocator.hh b/source/blender/blenlib/BLI_linear_allocator.hh index e2bb3ce02cb..f968f9f15ce 100644 --- a/source/blender/blenlib/BLI_linear_allocator.hh +++ b/source/blender/blenlib/BLI_linear_allocator.hh @@ -35,7 +35,7 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya private: Allocator m_allocator; Vector<void *> m_owned_buffers; - Vector<ArrayRef<char>> m_unused_borrowed_buffers; + Vector<Span<char>> m_unused_borrowed_buffers; uintptr_t m_current_begin; uintptr_t m_current_end; @@ -104,9 +104,9 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya * * This method only allocates memory and does not construct the instance. */ - template<typename T> MutableArrayRef<T> allocate_array(uint size) + template<typename T> MutableSpan<T> allocate_array(uint size) { - return MutableArrayRef<T>((T *)this->allocate(sizeof(T) * size, alignof(T)), size); + return MutableSpan<T>((T *)this->allocate(sizeof(T) * size, alignof(T)), size); } /** @@ -127,9 +127,9 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya /** * Copy the given array into a memory buffer provided by this allocator. */ - template<typename T> MutableArrayRef<T> construct_array_copy(ArrayRef<T> src) + template<typename T> MutableSpan<T> construct_array_copy(Span<T> src) { - MutableArrayRef<T> dst = this->allocate_array<T>(src.size()); + MutableSpan<T> dst = this->allocate_array<T>(src.size()); uninitialized_copy_n(src.data(), src.size(), dst.data()); return dst; } @@ -146,14 +146,14 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya return StringRefNull((const char *)buffer); } - MutableArrayRef<void *> allocate_elements_and_pointer_array(uint element_amount, - uint element_size, - uint element_alignment) + MutableSpan<void *> allocate_elements_and_pointer_array(uint element_amount, + uint element_size, + uint element_alignment) { void *pointer_buffer = this->allocate(element_amount * sizeof(void *), alignof(void *)); void *elements_buffer = this->allocate(element_amount * element_size, element_alignment); - MutableArrayRef<void *> pointers((void **)pointer_buffer, element_amount); + MutableSpan<void *> pointers((void **)pointer_buffer, element_amount); void *next_element_buffer = elements_buffer; for (uint i : IndexRange(element_amount)) { pointers[i] = next_element_buffer; @@ -164,11 +164,11 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya } template<typename T, typename... Args> - ArrayRef<T *> construct_elements_and_pointer_array(uint n, Args &&... args) + Span<T *> construct_elements_and_pointer_array(uint n, Args &&... args) { - MutableArrayRef<void *> void_pointers = this->allocate_elements_and_pointer_array( + MutableSpan<void *> void_pointers = this->allocate_elements_and_pointer_array( n, sizeof(T), alignof(T)); - MutableArrayRef<T *> pointers = void_pointers.cast<T *>(); + MutableSpan<T *> pointers = void_pointers.cast<T *>(); for (uint i : IndexRange(n)) { new (pointers[i]) T(std::forward<Args>(args)...); @@ -183,7 +183,7 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya */ void provide_buffer(void *buffer, uint size) { - m_unused_borrowed_buffers.append(ArrayRef<char>((char *)buffer, size)); + m_unused_borrowed_buffers.append(Span<char>((char *)buffer, size)); } template<size_t Size, size_t Alignment> @@ -196,7 +196,7 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya void allocate_new_buffer(uint min_allocation_size) { for (uint i : m_unused_borrowed_buffers.index_range()) { - ArrayRef<char> buffer = m_unused_borrowed_buffers[i]; + Span<char> buffer = m_unused_borrowed_buffers[i]; if (buffer.size() >= min_allocation_size) { m_unused_borrowed_buffers.remove_and_reorder(i); m_current_begin = (uintptr_t)buffer.begin(); |