[Bf-blender-cvs] [1cd8a438bb5] master: Cleanup: simplify field evaluation
Jacques Lucke
noreply at git.blender.org
Sun Sep 26 23:30:43 CEST 2021
Commit: 1cd8a438bb59d0e9e5160e8c91f9c937aab8195f
Author: Jacques Lucke
Date: Sun Sep 26 23:19:31 2021 +0200
Branches: master
https://developer.blender.org/rB1cd8a438bb59d0e9e5160e8c91f9c937aab8195f
Cleanup: simplify field evaluation
===================================================================
M source/blender/functions/intern/field.cc
===================================================================
diff --git a/source/blender/functions/intern/field.cc b/source/blender/functions/intern/field.cc
index 88e4e5ccd71..39688ef3daf 100644
--- a/source/blender/functions/intern/field.cc
+++ b/source/blender/functions/intern/field.cc
@@ -260,20 +260,6 @@ static void build_multi_function_procedure_for_fields(MFProcedure &procedure,
BLI_assert(procedure.validate());
}
-/**
- * Utility class that destructs elements from a partially initialized array.
- */
-struct PartiallyInitializedArray : NonCopyable, NonMovable {
- void *buffer;
- IndexMask mask;
- const CPPType *type;
-
- ~PartiallyInitializedArray()
- {
- this->type->destruct_indices(this->buffer, this->mask);
- }
-};
-
/**
* Evaluate fields in the given context. If possible, multiple fields should be evaluated together,
* because that can be more efficient when they share common sub-fields.
@@ -387,11 +373,11 @@ Vector<const GVArray *> evaluate_fields(ResourceScope &scope,
/* Allocate a new buffer for the computed result. */
buffer = scope.linear_allocator().allocate(type.size() * array_size, type.alignment());
- /* Make sure that elements in the buffer will be destructed. */
- PartiallyInitializedArray &destruct_helper = scope.construct<PartiallyInitializedArray>();
- destruct_helper.buffer = buffer;
- destruct_helper.mask = mask;
- destruct_helper.type = &type;
+ if (!type.is_trivially_destructible()) {
+ /* Destruct values in the end. */
+ scope.add_destruct_call(
+ [buffer, mask, &type]() { type.destruct_indices(buffer, mask); });
+ }
r_varrays[out_index] = &scope.construct<GVArray_For_GSpan>(
GSpan{type, buffer, array_size});
@@ -435,11 +421,11 @@ Vector<const GVArray *> evaluate_fields(ResourceScope &scope,
/* Allocate memory where the computed value will be stored in. */
void *buffer = scope.linear_allocator().allocate(type.size(), type.alignment());
- /* Use this to make sure that the value is destructed in the end. */
- PartiallyInitializedArray &destruct_helper = scope.construct<PartiallyInitializedArray>();
- destruct_helper.buffer = buffer;
- destruct_helper.mask = IndexRange(mask_size);
- destruct_helper.type = &type;
+ if (!type.is_trivially_destructible() && mask_size > 0) {
+ BLI_assert(mask_size == 1);
+ /* Destruct value in the end. */
+ scope.add_destruct_call([buffer, &type]() { type.destruct(buffer); });
+ }
/* Pass output buffer to the procedure executor. */
mf_params.add_uninitialized_single_output({type, buffer, mask_size});
More information about the Bf-blender-cvs
mailing list