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-08-28 22:33:03 +0300
committerHans Goudey <h.goudey@me.com>2022-08-28 22:33:03 +0300
commit67f3259c54657996d47112967c9b982f78ebfe6e (patch)
tree175eef61ff9e52044c56344e47aa93ac40f4c29c /source/blender/blenlib/BLI_virtual_array.hh
parent28750bcf7e8b73d9da015898a3c0f21ef5d761f2 (diff)
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
Diffstat (limited to 'source/blender/blenlib/BLI_virtual_array.hh')
-rw-r--r--source/blender/blenlib/BLI_virtual_array.hh14
1 files changed, 14 insertions, 0 deletions
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 <optional>
+
#include "BLI_any.hh"
#include "BLI_array.hh"
#include "BLI_index_mask.hh"
@@ -803,6 +805,18 @@ template<typename T> class VArrayCommon {
}
/**
+ * Return the value that is returned for every index, if the array is stored as a single value.
+ */
+ std::optional<T> get_if_single() const
+ {
+ const CommonVArrayInfo info = impl_->common_info();
+ if (info.type != CommonVArrayInfo::Type::Single) {
+ return std::nullopt;
+ }
+ return *static_cast<const T *>(info.data);
+ }
+
+ /**
* Return true when the other virtual references the same underlying memory.
*/
bool is_same(const VArrayCommon<T> &other) const