From 2b1dc0a44ef9e2faaa18e85472423f57895a5481 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sun, 26 Jan 2025 20:08:04 +0100 Subject: [PATCH] Cleanup: Various clang-tidy warnings in functions Pull Request: https://projects.blender.org/blender/blender/pulls/133734 --- source/blender/functions/FN_field.hh | 6 +-- source/blender/functions/FN_lazy_function.hh | 1 - .../functions/FN_lazy_function_execute.hh | 4 +- source/blender/functions/FN_multi_function.hh | 2 +- .../functions/FN_multi_function_builder.hh | 46 +++++++++---------- .../functions/intern/lazy_function_execute.cc | 4 +- .../multi_function_procedure_executor.cc | 18 ++++---- .../functions/tests/FN_lazy_function_test.cc | 1 - 8 files changed, 39 insertions(+), 43 deletions(-) diff --git a/source/blender/functions/FN_field.hh b/source/blender/functions/FN_field.hh index 1a6b8c5ecfd..32f6b78ab19 100644 --- a/source/blender/functions/FN_field.hh +++ b/source/blender/functions/FN_field.hh @@ -232,7 +232,7 @@ class FieldOperation : public FieldNode { public: FieldOperation(std::shared_ptr function, Vector inputs = {}); FieldOperation(const mf::MultiFunction &function, Vector inputs = {}); - ~FieldOperation(); + ~FieldOperation() override; Span inputs() const; const mf::MultiFunction &multi_function() const; @@ -273,7 +273,7 @@ class FieldInput : public FieldNode { public: FieldInput(const CPPType &type, std::string debug_name = ""); - ~FieldInput(); + ~FieldInput() override; /** * Get the value of this specific input based on the given context. The returned virtual array, @@ -298,7 +298,7 @@ class FieldConstant : public FieldNode { public: FieldConstant(const CPPType &type, const void *value); - ~FieldConstant(); + ~FieldConstant() override; const CPPType &output_cpp_type(int output_index) const override; const CPPType &type() const; diff --git a/source/blender/functions/FN_lazy_function.hh b/source/blender/functions/FN_lazy_function.hh index 9b81ad911b6..f1220bb6826 100644 --- a/source/blender/functions/FN_lazy_function.hh +++ b/source/blender/functions/FN_lazy_function.hh @@ -139,7 +139,6 @@ class Params { std::atomic allow_multi_threading_; #endif - public: Params(const LazyFunction &fn, bool allow_multi_threading_initially); /** diff --git a/source/blender/functions/FN_lazy_function_execute.hh b/source/blender/functions/FN_lazy_function_execute.hh index bd8a7b9be3e..5d62ee84303 100644 --- a/source/blender/functions/FN_lazy_function_execute.hh +++ b/source/blender/functions/FN_lazy_function_execute.hh @@ -99,7 +99,7 @@ inline void execute_lazy_function_eagerly_impl(const LazyFunction &fn, [&]() { constexpr size_t I = InIndices; /* Use `typedef` instead of `using` to work around a compiler bug. */ - typedef Inputs T; + using T = Inputs; const CPPType &type = CPPType::get(); input_pointers[I] = {type, &std::get(inputs)}; }(), @@ -108,7 +108,7 @@ inline void execute_lazy_function_eagerly_impl(const LazyFunction &fn, [&]() { constexpr size_t I = OutIndices; /* Use `typedef` instead of `using` to work around a compiler bug. */ - typedef Outputs T; + using T = Outputs; const CPPType &type = CPPType::get(); output_pointers[I] = {type, std::get(outputs)}; }(), diff --git a/source/blender/functions/FN_multi_function.hh b/source/blender/functions/FN_multi_function.hh index d4f61187a1c..59d135a7a0a 100644 --- a/source/blender/functions/FN_multi_function.hh +++ b/source/blender/functions/FN_multi_function.hh @@ -44,7 +44,7 @@ class MultiFunction : NonCopyable, NonMovable { const Signature *signature_ref_ = nullptr; public: - virtual ~MultiFunction() {} + virtual ~MultiFunction() = default; /** * The result is the same as using #call directly but this method has some additional features. diff --git a/source/blender/functions/FN_multi_function_builder.hh b/source/blender/functions/FN_multi_function_builder.hh index 6a2d4cc2d22..1f39ca2bf87 100644 --- a/source/blender/functions/FN_multi_function_builder.hh +++ b/source/blender/functions/FN_multi_function_builder.hh @@ -65,8 +65,8 @@ struct AllSpanOrSingle { const std::tuple &loaded_params) const { return std::make_tuple([&]() { - typedef ParamTags ParamTag; - typedef typename ParamTag::base_type T; + using ParamTag = ParamTags; + using T = typename ParamTag::base_type; if constexpr (ParamTag::category == ParamCategory::SingleInput) { const GVArrayImpl &varray_impl = *std::get(loaded_params); return GVArrayDevirtualizer{varray_impl}; @@ -97,8 +97,8 @@ template struct SomeSpanOrSingle { const std::tuple &loaded_params) const { return std::make_tuple([&]() { - typedef ParamTags ParamTag; - typedef typename ParamTag::base_type T; + using ParamTag = ParamTags; + using T = typename ParamTag::base_type; if constexpr (ParamTag::category == ParamCategory::SingleInput) { constexpr bool UseSpan = ValueSequence::template contains(); @@ -216,8 +216,8 @@ inline void execute_materialized(TypeSequence /*param_tags*/, /* Setup information for all parameters. */ [&] { /* Use `typedef` instead of `using` to work around a compiler bug. */ - typedef ParamTags ParamTag; - typedef typename ParamTag::base_type T; + using ParamTag = ParamTags; + using T = typename ParamTag::base_type; [[maybe_unused]] MaterializeArgInfo &arg_info = std::get(args_info); if constexpr (ParamTag::category == ParamCategory::SingleInput) { const GVArrayImpl &varray_impl = *std::get(loaded_params); @@ -258,8 +258,8 @@ inline void execute_materialized(TypeSequence /*param_tags*/, ( [&] { /* Use `typedef` instead of `using` to work around a compiler bug. */ - typedef ParamTags ParamTag; - typedef typename ParamTag::base_type T; + using ParamTag = ParamTags; + using T = typename ParamTag::base_type; if constexpr (ParamTag::category == ParamCategory::SingleMutable) { T *tmp_buffer = std::get(temporary_buffers).ptr(); T *param_buffer = std::get(loaded_params); @@ -317,11 +317,9 @@ inline void execute_materialized(TypeSequence /*param_tags*/, T *param_buffer = std::get(loaded_params); return param_buffer + mask_start; } - else { - /* Use the temporary buffer. The values will have to be copied out of that - * buffer into the caller-provided buffer afterwards. */ - return const_cast(tmp_buffer); - } + /* Use the temporary buffer. The values will have to be copied out of that + * buffer into the caller-provided buffer afterwards. */ + return tmp_buffer; } }()...); @@ -330,8 +328,8 @@ inline void execute_materialized(TypeSequence /*param_tags*/, ( [&] { /* Use `typedef` instead of `using` to work around a compiler bug. */ - typedef ParamTags ParamTag; - typedef typename ParamTag::base_type T; + using ParamTag = ParamTags; + using T = typename ParamTag::base_type; if constexpr (ELEM(ParamTag::category, ParamCategory::SingleOutput, ParamCategory::SingleMutable)) @@ -351,8 +349,8 @@ inline void execute_materialized(TypeSequence /*param_tags*/, /* Destruct values that have been materialized before. */ [&] { /* Use `typedef` instead of `using` to work around a compiler bug. */ - typedef ParamTags ParamTag; - typedef typename ParamTag::base_type T; + using ParamTag = ParamTags; + using T = typename ParamTag::base_type; [[maybe_unused]] MaterializeArgInfo &arg_info = std::get(args_info); if constexpr (ParamTag::category == ParamCategory::SingleInput) { if (arg_info.mode == MaterializeArgMode::Materialized) { @@ -368,8 +366,8 @@ inline void execute_materialized(TypeSequence /*param_tags*/, /* Destruct buffers for single value inputs. */ [&] { /* Use `typedef` instead of `using` to work around a compiler bug. */ - typedef ParamTags ParamTag; - typedef typename ParamTag::base_type T; + using ParamTag = ParamTags; + using T = typename ParamTag::base_type; [[maybe_unused]] MaterializeArgInfo &arg_info = std::get(args_info); if constexpr (ParamTag::category == ParamCategory::SingleInput) { if (arg_info.mode == MaterializeArgMode::Single) { @@ -394,8 +392,8 @@ inline void execute_element_fn_as_multi_function(const ElementFn element_fn, /* Contains `const GVArrayImpl *` for inputs and `T *` for outputs. */ const auto loaded_params = std::make_tuple([&]() { /* Use `typedef` instead of `using` to work around a compiler bug. */ - typedef ParamTags ParamTag; - typedef typename ParamTag::base_type T; + using ParamTag = ParamTags; + using T = typename ParamTag::base_type; if constexpr (ParamTag::category == ParamCategory::SingleInput) { return params.readonly_single_input(I).get_implementation(); @@ -463,8 +461,8 @@ inline void execute_element_fn_as_multi_function(const ElementFn element_fn, execute_array( TypeSequence(), std::index_sequence(), element_fn, segment, [&]() { /* Use `typedef` instead of `using` to work around a compiler bug. */ - typedef ParamTags ParamTag; - typedef typename ParamTag::base_type T; + using ParamTag = ParamTags; + using T = typename ParamTag::base_type; if constexpr (ParamTag::category == ParamCategory::SingleInput) { const GVArrayImpl &varray_impl = *std::get(loaded_params); return GVArray(&varray_impl).typed(); @@ -753,7 +751,7 @@ class CustomMF_GenericConstant : public MultiFunction { public: CustomMF_GenericConstant(const CPPType &type, const void *value, bool make_value_copy); - ~CustomMF_GenericConstant(); + ~CustomMF_GenericConstant() override; void call(const IndexMask &mask, Params params, Context context) const override; uint64_t hash() const override; bool equals(const MultiFunction &other) const override; diff --git a/source/blender/functions/intern/lazy_function_execute.cc b/source/blender/functions/intern/lazy_function_execute.cc index eb446cbbea7..8dccd518ed3 100644 --- a/source/blender/functions/intern/lazy_function_execute.cc +++ b/source/blender/functions/intern/lazy_function_execute.cc @@ -109,7 +109,7 @@ void *RemappedParams::get_output_data_ptr_impl(const int index) void RemappedParams::output_set_impl(const int index) { - return base_params_.output_set(output_map_[index]); + base_params_.output_set(output_map_[index]); } bool RemappedParams::output_was_set_impl(const int index) const @@ -124,7 +124,7 @@ lf::ValueUsage RemappedParams::get_output_usage_impl(const int index) const void RemappedParams::set_input_unused_impl(const int index) { - return base_params_.set_input_unused(input_map_[index]); + base_params_.set_input_unused(input_map_[index]); } bool RemappedParams::try_enable_multi_threading_impl() diff --git a/source/blender/functions/intern/multi_function_procedure_executor.cc b/source/blender/functions/intern/multi_function_procedure_executor.cc index 4d54b82bef0..121287f1b99 100644 --- a/source/blender/functions/intern/multi_function_procedure_executor.cc +++ b/source/blender/functions/intern/multi_function_procedure_executor.cc @@ -45,7 +45,7 @@ struct VariableValue { /* This variable is the unmodified virtual array from the caller. */ struct VariableValue_GVArray : public VariableValue { - static inline constexpr ValueType static_type = ValueType::GVArray; + static constexpr ValueType static_type = ValueType::GVArray; const GVArray &data; VariableValue_GVArray(const GVArray &data) : VariableValue(static_type), data(data) @@ -57,7 +57,7 @@ struct VariableValue_GVArray : public VariableValue { /* This variable has a different value for every index. Some values may be uninitialized. The span * may be owned by the caller. */ struct VariableValue_Span : public VariableValue { - static inline constexpr ValueType static_type = ValueType::Span; + static constexpr ValueType static_type = ValueType::Span; void *data; bool owned; @@ -68,7 +68,7 @@ struct VariableValue_Span : public VariableValue { /* This variable is the unmodified virtual vector array from the caller. */ struct VariableValue_GVVectorArray : public VariableValue { - static inline constexpr ValueType static_type = ValueType::GVVectorArray; + static constexpr ValueType static_type = ValueType::GVVectorArray; const GVVectorArray &data; VariableValue_GVVectorArray(const GVVectorArray &data) : VariableValue(static_type), data(data) @@ -78,7 +78,7 @@ struct VariableValue_GVVectorArray : public VariableValue { /* This variable has a different vector for every index. */ struct VariableValue_GVectorArray : public VariableValue { - static inline constexpr ValueType static_type = ValueType::GVectorArray; + static constexpr ValueType static_type = ValueType::GVectorArray; GVectorArray &data; bool owned; @@ -90,7 +90,7 @@ struct VariableValue_GVectorArray : public VariableValue { /* This variable has the same value for every index. */ struct VariableValue_OneSingle : public VariableValue { - static inline constexpr ValueType static_type = ValueType::OneSingle; + static constexpr ValueType static_type = ValueType::OneSingle; void *data; bool is_initialized = false; @@ -99,7 +99,7 @@ struct VariableValue_OneSingle : public VariableValue { /* This variable has the same vector for every index. */ struct VariableValue_OneVector : public VariableValue { - static inline constexpr ValueType static_type = ValueType::OneVector; + static constexpr ValueType static_type = ValueType::OneVector; GVectorArray &data; VariableValue_OneVector(GVectorArray &data) : VariableValue(static_type), data(data) {} @@ -124,7 +124,7 @@ class ValueAllocator : NonCopyable, NonMovable { * Allocate with 64 byte alignment for better reusability of buffers and improved cache * performance. */ - static constexpr inline int min_alignment = 64; + static constexpr int min_alignment = 64; /** All buffers in the free-lists below have been allocated with this allocator. */ LinearAllocator<> &linear_allocator_; @@ -143,8 +143,8 @@ class ValueAllocator : NonCopyable, NonMovable { Map> span_buffers_free_lists_; /** Cache buffers for single values of different types. */ - static constexpr inline int small_value_max_size = 16; - static constexpr inline int small_value_max_alignment = 8; + static constexpr int small_value_max_size = 16; + static constexpr int small_value_max_alignment = 8; Stack small_single_value_free_list_; Map> single_value_free_lists_; diff --git a/source/blender/functions/tests/FN_lazy_function_test.cc b/source/blender/functions/tests/FN_lazy_function_test.cc index ada673ad507..ca5b7d11395 100644 --- a/source/blender/functions/tests/FN_lazy_function_test.cc +++ b/source/blender/functions/tests/FN_lazy_function_test.cc @@ -9,7 +9,6 @@ #include "FN_lazy_function_graph_executor.hh" #include "BLI_task.h" -#include "BLI_timeit.hh" namespace blender::fn::lazy_function::tests {