From 67f3259c54657996d47112967c9b982f78ebfe6e Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Sun, 28 Aug 2022 14:33:03 -0500 Subject: Curves: Avoid creating types array when unnecessary When the curve type attribute doesn't exist, there is no reason to create an array for it only to fill the default value, which will add overhead to subsequent "add" operations. I added a "get_if_single" method to virtual array to simplify this check. Also use the existing functions for filling curve types. Differential Revision: https://developer.blender.org/D15560 --- source/blender/blenlib/BLI_virtual_array.hh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source/blender/blenlib/BLI_virtual_array.hh') diff --git a/source/blender/blenlib/BLI_virtual_array.hh b/source/blender/blenlib/BLI_virtual_array.hh index 7eab960b302..00677cf28a2 100644 --- a/source/blender/blenlib/BLI_virtual_array.hh +++ b/source/blender/blenlib/BLI_virtual_array.hh @@ -23,6 +23,8 @@ * see of the increased compile time and binary size is worth it. */ +#include + #include "BLI_any.hh" #include "BLI_array.hh" #include "BLI_index_mask.hh" @@ -802,6 +804,18 @@ template class VArrayCommon { return *static_cast(info.data); } + /** + * Return the value that is returned for every index, if the array is stored as a single value. + */ + std::optional get_if_single() const + { + const CommonVArrayInfo info = impl_->common_info(); + if (info.type != CommonVArrayInfo::Type::Single) { + return std::nullopt; + } + return *static_cast(info.data); + } + /** * Return true when the other virtual references the same underlying memory. */ -- cgit v1.2.3