From dee0b56b9216de8f37589b15be2d21cc1b946773 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 14 Sep 2021 16:08:09 +0200 Subject: Cleanup: simplify resource scope methods Previously, a debug name had to be passed to all methods that added a resource to the `ResourceScope`. The idea was that this would make it easier to find certain bugs. In reality I never found this to be useful, and it was mostly annoying. The thing is, something that is in a resource scope never leaks (unless the resource scope is not destructed of course). Removing the name parameter makes the structure easier to use. --- source/blender/functions/FN_field.hh | 14 +++++----- .../blender/functions/FN_multi_function_params.hh | 30 ++++++++++------------ source/blender/functions/intern/field.cc | 20 +++++++-------- source/blender/functions/tests/FN_field_test.cc | 2 +- 4 files changed, 31 insertions(+), 35 deletions(-) (limited to 'source/blender/functions') diff --git a/source/blender/functions/FN_field.hh b/source/blender/functions/FN_field.hh index d6259bce435..d4375b625ce 100644 --- a/source/blender/functions/FN_field.hh +++ b/source/blender/functions/FN_field.hh @@ -381,7 +381,7 @@ class FieldEvaluator : NonMovable, NonCopyable { /** Same as #add_with_destination but typed. */ template int add_with_destination(Field field, VMutableArray &dst) { - GVMutableArray &varray = scope_.construct>(__func__, dst); + GVMutableArray &varray = scope_.construct>(dst); return this->add_with_destination(GField(std::move(field)), varray); } @@ -401,7 +401,7 @@ class FieldEvaluator : NonMovable, NonCopyable { */ template int add_with_destination(Field field, MutableSpan dst) { - GVMutableArray &varray = scope_.construct>(__func__, dst); + GVMutableArray &varray = scope_.construct>(dst); return this->add_with_destination(std::move(field), varray); } @@ -417,10 +417,10 @@ class FieldEvaluator : NonMovable, NonCopyable { { const int field_index = fields_to_evaluate_.append_and_get_index(std::move(field)); dst_varrays_.append(nullptr); - output_pointer_infos_.append(OutputPointerInfo{ - varray_ptr, [](void *dst, const GVArray &varray, ResourceScope &scope) { - *(const VArray **)dst = &*scope.construct>(__func__, varray); - }}); + output_pointer_infos_.append( + OutputPointerInfo{varray_ptr, [](void *dst, const GVArray &varray, ResourceScope &scope) { + *(const VArray **)dst = &*scope.construct>(varray); + }}); return field_index; } @@ -443,7 +443,7 @@ class FieldEvaluator : NonMovable, NonCopyable { template const VArray &get_evaluated(const int field_index) { const GVArray &varray = this->get_evaluated(field_index); - GVArray_Typed &typed_varray = scope_.construct>(__func__, varray); + GVArray_Typed &typed_varray = scope_.construct>(varray); return *typed_varray; } diff --git a/source/blender/functions/FN_multi_function_params.hh b/source/blender/functions/FN_multi_function_params.hh index cae105e7c19..fe4d2b90d80 100644 --- a/source/blender/functions/FN_multi_function_params.hh +++ b/source/blender/functions/FN_multi_function_params.hh @@ -62,25 +62,24 @@ class MFParamsBuilder { template void add_readonly_single_input_value(T value, StringRef expected_name = "") { - T *value_ptr = &scope_.add_value(std::move(value), __func__); + T *value_ptr = &scope_.add_value(std::move(value)); this->add_readonly_single_input(value_ptr, expected_name); } template void add_readonly_single_input(const T *value, StringRef expected_name = "") { - this->add_readonly_single_input(scope_.construct( - __func__, CPPType::get(), min_array_size_, value), - expected_name); + this->add_readonly_single_input( + scope_.construct(CPPType::get(), min_array_size_, value), + expected_name); } void add_readonly_single_input(const GSpan span, StringRef expected_name = "") { - this->add_readonly_single_input(scope_.construct(__func__, span), - expected_name); + this->add_readonly_single_input(scope_.construct(span), expected_name); } void add_readonly_single_input(GPointer value, StringRef expected_name = "") { - this->add_readonly_single_input(scope_.construct( - __func__, *value.type(), min_array_size_, value.get()), - expected_name); + this->add_readonly_single_input( + scope_.construct(*value.type(), min_array_size_, value.get()), + expected_name); } void add_readonly_single_input(const GVArray &ref, StringRef expected_name = "") { @@ -91,13 +90,13 @@ class MFParamsBuilder { void add_readonly_vector_input(const GVectorArray &vector_array, StringRef expected_name = "") { - this->add_readonly_vector_input( - scope_.construct(__func__, vector_array), expected_name); + this->add_readonly_vector_input(scope_.construct(vector_array), + expected_name); } void add_readonly_vector_input(const GSpan single_vector, StringRef expected_name = "") { this->add_readonly_vector_input( - scope_.construct(__func__, single_vector, min_array_size_), + scope_.construct(single_vector, min_array_size_), expected_name); } void add_readonly_vector_input(const GVVectorArray &ref, StringRef expected_name = "") @@ -225,7 +224,7 @@ class MFParams { template const VArray &readonly_single_input(int param_index, StringRef name = "") { const GVArray &array = this->readonly_single_input(param_index, name); - return builder_->scope_.construct>(__func__, array); + return builder_->scope_.construct>(array); } const GVArray &readonly_single_input(int param_index, StringRef name = "") { @@ -266,8 +265,7 @@ class MFParams { if (!type.is_trivially_destructible()) { /* Make sure the temporary elements will be destructed in the end. */ builder_->scope_.add_destruct_call( - [&type, buffer, mask = builder_->mask_]() { type.destruct_indices(buffer, mask); }, - __func__); + [&type, buffer, mask = builder_->mask_]() { type.destruct_indices(buffer, mask); }); } span = GMutableSpan{type, buffer, builder_->min_array_size_}; } @@ -278,7 +276,7 @@ class MFParams { const VVectorArray &readonly_vector_input(int param_index, StringRef name = "") { const GVVectorArray &vector_array = this->readonly_vector_input(param_index, name); - return builder_->scope_.construct>(__func__, vector_array); + return builder_->scope_.construct>(vector_array); } const GVVectorArray &readonly_vector_input(int param_index, StringRef name = "") { diff --git a/source/blender/functions/intern/field.cc b/source/blender/functions/intern/field.cc index 574a9e6284f..43f28efd002 100644 --- a/source/blender/functions/intern/field.cc +++ b/source/blender/functions/intern/field.cc @@ -92,7 +92,7 @@ static Vector get_field_context_inputs( if (varray == nullptr) { const CPPType &type = field_input.cpp_type(); varray = &scope.construct( - __func__, type, mask.min_array_size(), type.default_value()); + type, mask.min_array_size(), type.default_value()); } field_context_inputs.append(varray); } @@ -237,8 +237,8 @@ static void build_multi_function_procedure_for_fields(MFProcedure &procedure, if (!already_output_variables.add(variable)) { /* One variable can be output at most once. To output the same value twice, we have to make * a copy first. */ - const MultiFunction ©_fn = scope.construct( - __func__, "copy", variable->data_type()); + const MultiFunction ©_fn = scope.construct("copy", + variable->data_type()); variable = builder.add_call<1>(copy_fn, {variable})[0]; } builder.add_output_parameter(*variable); @@ -381,14 +381,13 @@ Vector evaluate_fields(ResourceScope &scope, 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( - __func__); + PartiallyInitializedArray &destruct_helper = scope.construct(); destruct_helper.buffer = buffer; destruct_helper.mask = mask; destruct_helper.type = &type; r_varrays[out_index] = &scope.construct( - __func__, GSpan{type, buffer, array_size}); + GSpan{type, buffer, array_size}); } else { /* Write the result into the existing span. */ @@ -427,8 +426,7 @@ Vector evaluate_fields(ResourceScope &scope, 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( - __func__); + PartiallyInitializedArray &destruct_helper = scope.construct(); destruct_helper.buffer = buffer; destruct_helper.mask = IndexRange(1); destruct_helper.type = &type; @@ -439,7 +437,7 @@ Vector evaluate_fields(ResourceScope &scope, /* Create virtual array that can be used after the procedure has been executed below. */ const int out_index = constant_field_indices[i]; r_varrays[out_index] = &scope.construct( - __func__, type, array_size, buffer); + type, array_size, buffer); } procedure_executor.call(IndexRange(1), mf_params, mf_context); @@ -608,7 +606,7 @@ int FieldEvaluator::add_with_destination(GField field, GVMutableArray &dst) int FieldEvaluator::add_with_destination(GField field, GMutableSpan dst) { - GVMutableArray &varray = scope_.construct(__func__, dst); + GVMutableArray &varray = scope_.construct(dst); return this->add_with_destination(std::move(field), varray); } @@ -661,7 +659,7 @@ IndexMask FieldEvaluator::get_evaluated_as_mask(const int field_index) return IndexRange(0); } - return scope_.add_value(indices_from_selection(*typed_varray), __func__).as_span(); + return scope_.add_value(indices_from_selection(*typed_varray)).as_span(); } } // namespace blender::fn diff --git a/source/blender/functions/tests/FN_field_test.cc b/source/blender/functions/tests/FN_field_test.cc index 1c2d5c8eaad..041cdbd0f00 100644 --- a/source/blender/functions/tests/FN_field_test.cc +++ b/source/blender/functions/tests/FN_field_test.cc @@ -41,7 +41,7 @@ class IndexFieldInput final : public FieldInput { auto index_func = [](int i) { return i; }; return &scope.construct< GVArray_For_EmbeddedVArray>>( - __func__, mask.min_array_size(), mask.min_array_size(), index_func); + mask.min_array_size(), mask.min_array_size(), index_func); } }; -- cgit v1.2.3