diff options
author | Jacques Lucke <jacques@blender.org> | 2022-04-07 20:28:41 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-04-07 20:28:41 +0300 |
commit | a5beca7ba0daaca81805dbbf8857378a5bde6414 (patch) | |
tree | 6706ff6ed48e3e9bc5288d40170f711cf2d7617b /source/blender/blenlib/BLI_span.hh | |
parent | 67c42e7f034aad2564d8cde1a9901d9629527daa (diff) |
BLI: inline fast path of IndexRange::as_span
This frequently showed up in profiling but shouldn't.
This also updates the code to use atomics for more correctness and
adds multi-threading for better performance.
Diffstat (limited to 'source/blender/blenlib/BLI_span.hh')
-rw-r--r-- | source/blender/blenlib/BLI_span.hh | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_span.hh b/source/blender/blenlib/BLI_span.hh index 9ab096094de..0f3fcea1270 100644 --- a/source/blender/blenlib/BLI_span.hh +++ b/source/blender/blenlib/BLI_span.hh @@ -722,4 +722,16 @@ template<typename T> class MutableSpan { } }; +/** This is defined here, because in `BLI_index_range.hh` `Span` is not yet defined. */ +inline Span<int64_t> IndexRange::as_span() const +{ + const int64_t min_required_size = start_ + size_; + const int64_t current_array_size = s_current_array_size.load(std::memory_order_acquire); + const int64_t *current_array = s_current_array.load(std::memory_order_acquire); + if (min_required_size <= current_array_size) { + return Span<int64_t>(current_array + start_, size_); + } + return this->as_span_internal(); +} + } /* namespace blender */ |