From 6e879c39987cb977299ee8ab09158c283d70a351 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 4 Jul 2022 15:30:42 -0500 Subject: 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 --- source/blender/blenlib/intern/generic_virtual_array.cc | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source/blender/blenlib/intern') 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(*this, slice); } -- cgit v1.2.3