diff options
author | Jacques Lucke <mail@jlucke.com> | 2020-02-01 13:58:50 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2020-02-01 13:58:50 +0300 |
commit | 599e8f7bb10d7aeeab2060f0b6124f11e9944f91 (patch) | |
tree | ad5de99f0f49c4296f96e21233796ec127d6211d | |
parent | 26f4fa9de73b46b82de21660f371a5e80dcfd600 (diff) |
cleanup same size asserts
16 files changed, 44 insertions, 22 deletions
diff --git a/source/blender/blenlib/BLI_array_ref.h b/source/blender/blenlib/BLI_array_ref.h index 4c96e156aa5..6cc96cedc83 100644 --- a/source/blender/blenlib/BLI_array_ref.h +++ b/source/blender/blenlib/BLI_array_ref.h @@ -518,6 +518,28 @@ template<typename T> ArrayRef<T> ref_c_array(const T *array, uint size) return ArrayRef<T>(array, size); } +template<typename T1, typename T2> void assert_same_size(const T1 &v1, const T2 &v2) +{ + UNUSED_VARS_NDEBUG(v1, v2); +#ifdef DEBUG + uint size = v1.size(); + BLI_assert(size == v1.size()); + BLI_assert(size == v2.size()); +#endif +} + +template<typename T1, typename T2, typename T3> +void assert_same_size(const T1 &v1, const T2 &v2, const T3 &v3) +{ + UNUSED_VARS_NDEBUG(v1, v2, v3); +#ifdef DEBUG + uint size = v1.size(); + BLI_assert(size == v1.size()); + BLI_assert(size == v2.size()); + BLI_assert(size == v3.size()); +#endif +} + } /* namespace BLI */ #endif /* __BLI_ARRAY_REF_H__ */ diff --git a/source/blender/blenlib/BLI_buffer_cache.h b/source/blender/blenlib/BLI_buffer_cache.h index 6d590b4f5ff..9d70fe87633 100644 --- a/source/blender/blenlib/BLI_buffer_cache.h +++ b/source/blender/blenlib/BLI_buffer_cache.h @@ -32,7 +32,7 @@ class BufferCache { ~BufferCache() { - BLI_assert(m_cached_buffers.size() == m_all_buffers.size()); + assert_same_size(m_cached_buffers, m_all_buffers); for (BufferHead *head : m_all_buffers) { MEM_freeN((void *)head); diff --git a/source/blender/blenlib/BLI_float_interval.h b/source/blender/blenlib/BLI_float_interval.h index 3ad3a56a412..ce37fa61607 100644 --- a/source/blender/blenlib/BLI_float_interval.h +++ b/source/blender/blenlib/BLI_float_interval.h @@ -38,7 +38,7 @@ class FloatInterval { void value_at(ArrayRef<float> factors, MutableArrayRef<float> r_values) { - BLI_assert(factors.size() == r_values.size()); + assert_same_size(factors, r_values); for (uint i : factors.index_range()) { r_values[i] = this->value_at(factors[i]); } diff --git a/source/blender/blenlib/BLI_virtual_list_list_ref.h b/source/blender/blenlib/BLI_virtual_list_list_ref.h index 5ba76186b80..ebcda7eb438 100644 --- a/source/blender/blenlib/BLI_virtual_list_list_ref.h +++ b/source/blender/blenlib/BLI_virtual_list_list_ref.h @@ -48,7 +48,7 @@ template<typename T> class VirtualListListRef { static VirtualListListRef FromListOfStartPointers(ArrayRef<const T *> starts, ArrayRef<uint> sizes) { - BLI_assert(starts.size() == sizes.size()); + assert_same_size(starts, sizes); VirtualListListRef list; list.m_virtual_size = starts.size(); list.m_category = Category::ListOfStartPointers; diff --git a/source/blender/functions/FN_generic_virtual_list_list_ref.h b/source/blender/functions/FN_generic_virtual_list_list_ref.h index 32e80d721e7..e09df56eba1 100644 --- a/source/blender/functions/FN_generic_virtual_list_list_ref.h +++ b/source/blender/functions/FN_generic_virtual_list_list_ref.h @@ -66,7 +66,7 @@ class GenericVirtualListListRef { ArrayRef<const void *> starts, ArrayRef<uint> array_sizes) { - BLI_assert(starts.size() == array_sizes.size()); + BLI::assert_same_size(starts, array_sizes); return GenericVirtualListListRef::FromFullArrayList( type, starts.begin(), array_sizes.begin(), starts.size()); } diff --git a/source/blender/functions/FN_node_tree_multi_function_network.h b/source/blender/functions/FN_node_tree_multi_function_network.h index 05ae1517520..d528f56f92b 100644 --- a/source/blender/functions/FN_node_tree_multi_function_network.h +++ b/source/blender/functions/FN_node_tree_multi_function_network.h @@ -134,7 +134,7 @@ class FunctionTreeMFNetwork { void lookup_dummy_sockets(ArrayRef<const FOutputSocket *> fsockets, MutableArrayRef<const MFOutputSocket *> r_result) const { - BLI_assert(fsockets.size() == r_result.size()); + BLI::assert_same_size(fsockets, r_result); for (uint i : fsockets.index_range()) { r_result[i] = &this->lookup_socket(*fsockets[i]); } @@ -143,7 +143,7 @@ class FunctionTreeMFNetwork { void lookup_dummy_sockets(ArrayRef<const FInputSocket *> fsockets, MutableArrayRef<const MFInputSocket *> r_result) const { - BLI_assert(fsockets.size() == r_result.size()); + BLI::assert_same_size(fsockets, r_result); for (uint i : fsockets.index_range()) { r_result[i] = &this->lookup_dummy_socket(*fsockets[i]); } diff --git a/source/blender/functions/intern/attributes_ref.cc b/source/blender/functions/intern/attributes_ref.cc index 9571a58a19f..9fbf492f934 100644 --- a/source/blender/functions/intern/attributes_ref.cc +++ b/source/blender/functions/intern/attributes_ref.cc @@ -80,7 +80,7 @@ void MutableAttributesRef::destruct_and_reorder(IndexMask index_mask) void MutableAttributesRef::RelocateUninitialized(MutableAttributesRef from, MutableAttributesRef to) { - BLI_assert(from.size() == to.size()); + BLI::assert_same_size(from, to); BLI_assert(&from.info() == &to.info()); for (uint attribute_index : from.info().indices()) { @@ -131,8 +131,8 @@ void AttributesInfoDiff::update(uint capacity, ArrayRef<void *> old_buffers, MutableArrayRef<void *> new_buffers) const { - BLI_assert(old_buffers.size() == m_old_info->size()); - BLI_assert(new_buffers.size() == m_new_info->size()); + BLI::assert_same_size(old_buffers, *m_old_info); + BLI::assert_same_size(new_buffers, *m_new_info); for (uint new_index : m_new_info->indices()) { int old_index = m_new_to_old_mapping[new_index]; diff --git a/source/blender/functions/intern/generic_array_ref.cc b/source/blender/functions/intern/generic_array_ref.cc index fd6bb80e5c8..7004ee864da 100644 --- a/source/blender/functions/intern/generic_array_ref.cc +++ b/source/blender/functions/intern/generic_array_ref.cc @@ -5,7 +5,7 @@ namespace FN { void GenericMutableArrayRef::RelocateUninitialized(GenericMutableArrayRef from, GenericMutableArrayRef to) { - BLI_assert(from.size() == to.size()); + BLI::assert_same_size(from, to); BLI_assert(from.type() == to.type()); from.m_type->relocate_to_uninitialized_n(from.buffer(), to.buffer(), from.size()); diff --git a/source/blender/functions/intern/multi_function_network.cc b/source/blender/functions/intern/multi_function_network.cc index 9ed3166a35b..52e0d9689b7 100644 --- a/source/blender/functions/intern/multi_function_network.cc +++ b/source/blender/functions/intern/multi_function_network.cc @@ -113,8 +113,8 @@ MFBuilderDummyNode &MFNetworkBuilder::add_dummy(StringRef name, ArrayRef<StringRef> input_names, ArrayRef<StringRef> output_names) { - BLI_assert(input_types.size() == input_names.size()); - BLI_assert(output_types.size() == output_names.size()); + BLI::assert_same_size(input_types, input_names); + BLI::assert_same_size(output_types, output_names); auto &node = *m_allocator.construct<MFBuilderDummyNode>(); m_dummy_nodes.add_new(&node); diff --git a/source/blender/functions/intern/multi_functions/surface_hook.cc b/source/blender/functions/intern/multi_functions/surface_hook.cc index 8dc0b523eec..b890dc153fc 100644 --- a/source/blender/functions/intern/multi_functions/surface_hook.cc +++ b/source/blender/functions/intern/multi_functions/surface_hook.cc @@ -469,7 +469,7 @@ static BLI_NOINLINE void compute_triangle_areas(Mesh *mesh, ArrayRef<MLoopTri> triangles, MutableArrayRef<float> r_areas) { - BLI_assert(triangles.size() == r_areas.size()); + BLI::assert_same_size(triangles, r_areas); for (uint i : triangles.index_range()) { const MLoopTri &triangle = triangles[i]; @@ -529,7 +529,7 @@ static BLI_NOINLINE void vertex_weights_to_triangle_weights( ArrayRef<float> vertex_weights, MutableArrayRef<float> r_triangle_weights) { - BLI_assert(r_triangle_weights.size() == triangles.size()); + BLI::assert_same_size(r_triangle_weights, triangles); BLI_assert(mesh->totvert == vertex_weights.size()); for (uint triangle_index : triangles.index_range()) { diff --git a/source/blender/functions/intern/node_tree_multi_function_network/builder.h b/source/blender/functions/intern/node_tree_multi_function_network/builder.h index 4d08b821b72..895b28c82a6 100644 --- a/source/blender/functions/intern/node_tree_multi_function_network/builder.h +++ b/source/blender/functions/intern/node_tree_multi_function_network/builder.h @@ -103,7 +103,7 @@ class MFSocketByFSocketMapping { void add(ArrayRef<const FInputSocket *> fsockets, ArrayRef<MFBuilderInputSocket *> sockets) { - BLI_assert(fsockets.size() == sockets.size()); + BLI::assert_same_size(fsockets, sockets); for (uint i : fsockets.index_range()) { this->add(*fsockets[i], *sockets[i]); } @@ -111,7 +111,7 @@ class MFSocketByFSocketMapping { void add(ArrayRef<const FOutputSocket *> fsockets, ArrayRef<MFBuilderOutputSocket *> sockets) { - BLI_assert(fsockets.size() == sockets.size()); + BLI::assert_same_size(fsockets, sockets); for (uint i : fsockets.index_range()) { this->add(*fsockets[i], *sockets[i]); } diff --git a/source/blender/simulations/bparticles/emitters.cpp b/source/blender/simulations/bparticles/emitters.cpp index 3f0004751fd..773720eaf8e 100644 --- a/source/blender/simulations/bparticles/emitters.cpp +++ b/source/blender/simulations/bparticles/emitters.cpp @@ -166,7 +166,7 @@ static BLI_NOINLINE void compute_triangle_areas(Mesh *mesh, ArrayRef<MLoopTri> triangles, MutableArrayRef<float> r_areas) { - BLI_assert(triangles.size() == r_areas.size()); + BLI::assert_same_size(triangles, r_areas); for (uint i : triangles.index_range()) { const MLoopTri &triangle = triangles[i]; @@ -205,7 +205,7 @@ static BLI_NOINLINE void sample_looptris(Mesh *mesh, MutableArrayRef<float3> r_sampled_normals, MutableArrayRef<float3> r_sampled_bary_coords) { - BLI_assert(triangles_to_sample.size() == r_sampled_positions.size()); + BLI::assert_same_size(triangles_to_sample, r_sampled_positions); MLoop *loops = mesh->mloop; MVert *verts = mesh->mvert; diff --git a/source/blender/simulations/bparticles/particle_action.hpp b/source/blender/simulations/bparticles/particle_action.hpp index b52904a40d1..a50d5aefdf9 100644 --- a/source/blender/simulations/bparticles/particle_action.hpp +++ b/source/blender/simulations/bparticles/particle_action.hpp @@ -36,7 +36,7 @@ class ParticleActionContext { m_custom_context_ids(custom_context_ids), m_custom_contexts(custom_contexts) { - BLI_assert(m_custom_context_ids.size() == m_custom_contexts.size()); + BLI::assert_same_size(m_custom_context_ids, m_custom_contexts); } ArrayRef<BLI::class_id_t> custom_context_ids() const diff --git a/source/blender/simulations/bparticles/particle_allocator.cpp b/source/blender/simulations/bparticles/particle_allocator.cpp index 6c76d9d9c92..ae4abf1cc4d 100644 --- a/source/blender/simulations/bparticles/particle_allocator.cpp +++ b/source/blender/simulations/bparticles/particle_allocator.cpp @@ -19,7 +19,7 @@ void ParticleAllocator::initialize_new_particles(AttributesRefGroup &attributes_ MutableArrayRef<int32_t> particle_ids = attributes.get<int32_t>("ID"); IndexRange new_ids = m_state.get_new_particle_ids(attributes.size()); - BLI_assert(particle_ids.size() == new_ids.size()); + BLI::assert_same_size(particle_ids, new_ids); for (uint i = 0; i < new_ids.size(); i++) { particle_ids[i] = new_ids[i]; } diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp index 8214a3dff87..e05b4baa4d9 100644 --- a/source/blender/simulations/bparticles/simulate.cpp +++ b/source/blender/simulations/bparticles/simulate.cpp @@ -151,7 +151,7 @@ BLI_NOINLINE static void execute_events(BlockStepData &step_data, ArrayRef<float> current_times, ArrayRef<Event *> events) { - BLI_assert(events.size() == pindices_per_event.size()); + BLI::assert_same_size(events, pindices_per_event); for (uint event_index : events.index_range()) { Event *event = events[event_index]; diff --git a/source/blender/simulations/bparticles/world_state.hpp b/source/blender/simulations/bparticles/world_state.hpp index 01b4c29d81b..6de009e2b6f 100644 --- a/source/blender/simulations/bparticles/world_state.hpp +++ b/source/blender/simulations/bparticles/world_state.hpp @@ -49,7 +49,7 @@ struct VaryingFloat4x4 { float time_offset, MutableArrayRef<float4x4> r_results) const { - BLI_assert(times.size() == r_results.size()); + BLI::assert_same_size(times, r_results); for (uint i : times.index_range()) { r_results[i] = this->interpolate(times[i] + time_offset); } |