[Bf-blender-cvs] [6e879c39987] master: BLI: Use simpler sliced generic virtual arrays when possible

Hans Goudey noreply at git.blender.org
Mon Jul 4 22:31:24 CEST 2022


Commit: 6e879c39987cb977299ee8ab09158c283d70a351
Author: Hans Goudey
Date:   Mon Jul 4 15:30:42 2022 -0500
Branches: master
https://developer.blender.org/rB6e879c39987cb977299ee8ab09158c283d70a351

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

===================================================================

M	source/blender/blenlib/intern/generic_virtual_array.cc

===================================================================

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);
 }



More information about the Bf-blender-cvs mailing list