Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-07-04 23:30:42 +0300
committerHans Goudey <h.goudey@me.com>2022-07-04 23:30:42 +0300
commit6e879c39987cb977299ee8ab09158c283d70a351 (patch)
tree5247426798224ee7dba254d8199e1658fb40bee0 /source/blender/blenlib/intern/generic_virtual_array.cc
parent242bfd28ce5f469ed5cbec8958dceeb43dca9fcf (diff)
BLI: Use simpler sliced generic virtual arrays when possible
This is just a theoretical improvement currently, I won't try to justify it with some microbenchmark, but it should be better to use the specialized single and span virtual arrays when slicing a `GVArray`, since any use of `GVArrayImpl_For_SlicedGVArray` has extra overhead. Differential Revision: https://developer.blender.org/D15361
Diffstat (limited to 'source/blender/blenlib/intern/generic_virtual_array.cc')
-rw-r--r--source/blender/blenlib/intern/generic_virtual_array.cc9
1 files changed, 9 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/generic_virtual_array.cc b/source/blender/blenlib/intern/generic_virtual_array.cc
index 1f6e6cd6e18..532c7b9b626 100644
--- a/source/blender/blenlib/intern/generic_virtual_array.cc
+++ b/source/blender/blenlib/intern/generic_virtual_array.cc
@@ -688,6 +688,15 @@ GVArray GVArray::ForEmpty(const CPPType &type)
GVArray GVArray::slice(IndexRange slice) const
{
+ const CommonVArrayInfo info = this->common_info();
+ if (info.type == CommonVArrayInfo::Type::Single) {
+ return GVArray::ForSingle(this->type(), slice.size(), info.data);
+ }
+ /* Need to check for ownership, because otherwise the referenced data can be destructed when
+ * #this is destructed. */
+ if (info.type == CommonVArrayInfo::Type::Span && !info.may_have_ownership) {
+ return GVArray::ForSpan(GSpan(this->type(), info.data, this->size()).slice(slice));
+ }
return GVArray::For<GVArrayImpl_For_SlicedGVArray>(*this, slice);
}