[Bf-blender-cvs] [c50e5fcc344] master: Cleanup: use C++ style casts in various places
Jacques Lucke
noreply at git.blender.org
Fri Aug 7 18:56:23 CEST 2020
Commit: c50e5fcc344d00b03eb4a3141b5b45944c3570fd
Author: Jacques Lucke
Date: Fri Aug 7 18:24:59 2020 +0200
Branches: master
https://developer.blender.org/rBc50e5fcc344d00b03eb4a3141b5b45944c3570fd
Cleanup: use C++ style casts in various places
===================================================================
M source/blender/blenkernel/BKE_persistent_data_handle.hh
M source/blender/blenkernel/intern/simulation.cc
M source/blender/blenlib/BLI_allocator.hh
M source/blender/blenlib/BLI_array.hh
M source/blender/blenlib/BLI_color.hh
M source/blender/blenlib/BLI_float3.hh
M source/blender/blenlib/BLI_float4x4.hh
M source/blender/blenlib/BLI_hash.hh
M source/blender/blenlib/BLI_hash_tables.hh
M source/blender/blenlib/BLI_linear_allocator.hh
M source/blender/blenlib/BLI_listbase_wrapper.hh
M source/blender/blenlib/BLI_map.hh
M source/blender/blenlib/BLI_memory_utils.hh
M source/blender/blenlib/BLI_probing_strategies.hh
M source/blender/blenlib/BLI_rand.hh
M source/blender/blenlib/BLI_set.hh
M source/blender/blenlib/BLI_span.hh
M source/blender/blenlib/BLI_stack.hh
M source/blender/blenlib/BLI_string_ref.hh
M source/blender/blenlib/BLI_vector.hh
M source/blender/blenlib/BLI_vector_set.hh
M source/blender/blenlib/intern/rand.cc
M source/blender/blenlib/tests/BLI_linear_allocator_test.cc
M source/blender/blenlib/tests/BLI_span_test.cc
M source/blender/depsgraph/intern/builder/deg_builder_cache.cc
M source/blender/functions/FN_attributes_ref.hh
M source/blender/functions/FN_cpp_type.hh
M source/blender/functions/FN_generic_vector_array.hh
M source/blender/functions/FN_multi_function_builder.hh
M source/blender/functions/FN_multi_function_context.hh
M source/blender/functions/FN_multi_function_data_type.hh
M source/blender/functions/FN_multi_function_network.hh
M source/blender/functions/FN_spans.hh
M source/blender/functions/intern/multi_function_network.cc
M source/blender/functions/intern/multi_function_network_evaluation.cc
M source/blender/functions/intern/multi_function_network_optimization.cc
M source/blender/modifiers/intern/MOD_mask.cc
M source/blender/modifiers/intern/MOD_simulation.cc
M source/blender/nodes/NOD_derived_node_tree.hh
M source/blender/nodes/NOD_node_tree_multi_function.hh
M source/blender/nodes/NOD_node_tree_ref.hh
M source/blender/nodes/function/nodes/node_fn_random_float.cc
M source/blender/nodes/intern/derived_node_tree.cc
M source/blender/nodes/intern/node_tree_dependencies.cc
M source/blender/nodes/intern/node_tree_ref.cc
M source/blender/nodes/simulation/node_simulation_tree.cc
M source/blender/simulation/intern/particle_allocator.cc
M source/blender/simulation/intern/particle_mesh_emitter.cc
M source/blender/simulation/intern/simulation_solver_influences.hh
M source/blender/simulation/intern/simulation_update.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_persistent_data_handle.hh b/source/blender/blenkernel/BKE_persistent_data_handle.hh
index bcc84f9c9d0..42a853886d7 100644
--- a/source/blender/blenkernel/BKE_persistent_data_handle.hh
+++ b/source/blender/blenkernel/BKE_persistent_data_handle.hh
@@ -68,7 +68,7 @@ class PersistentDataHandle {
uint64_t hash() const
{
- return (uint64_t)handle_;
+ return static_cast<uint64_t>(handle_);
}
};
diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc
index c0fc8fcb464..6b03721cab8 100644
--- a/source/blender/blenkernel/intern/simulation.cc
+++ b/source/blender/blenkernel/intern/simulation.cc
@@ -295,21 +295,20 @@ using StateTypeMap = blender::Map<std::string, std::unique_ptr<SimulationStateTy
template<typename T>
static void add_state_type(StateTypeMap &map,
- const char *name,
void (*init)(T *state),
void (*reset)(T *state),
void (*remove)(T *state),
void (*copy)(const T *src, T *dst))
{
SimulationStateType state_type{
- name,
- (int)sizeof(T),
+ BKE_simulation_get_state_type_name<T>(),
+ static_cast<int>(sizeof(T)),
(StateInitFunction)init,
(StateResetFunction)reset,
(StateRemoveFunction)remove,
(StateCopyFunction)copy,
};
- map.add_new(name, std::make_unique<SimulationStateType>(state_type));
+ map.add_new(state_type.name, std::make_unique<SimulationStateType>(state_type));
}
static StateTypeMap init_state_types()
@@ -317,7 +316,6 @@ static StateTypeMap init_state_types()
StateTypeMap map;
add_state_type<ParticleSimulationState>(
map,
- SIM_TYPE_NAME_PARTICLE_SIMULATION,
[](ParticleSimulationState *state) { CustomData_reset(&state->attributes); },
[](ParticleSimulationState *state) {
CustomData_free(&state->attributes, state->tot_particles);
@@ -337,7 +335,6 @@ static StateTypeMap init_state_types()
add_state_type<ParticleMeshEmitterSimulationState>(
map,
- SIM_TYPE_NAME_PARTICLE_MESH_EMITTER,
[](ParticleMeshEmitterSimulationState *UNUSED(state)) {},
[](ParticleMeshEmitterSimulationState *state) { state->last_birth_time = 0.0f; },
[](ParticleMeshEmitterSimulationState *UNUSED(state)) {},
diff --git a/source/blender/blenlib/BLI_allocator.hh b/source/blender/blenlib/BLI_allocator.hh
index 3f753d1d81d..899c8499807 100644
--- a/source/blender/blenlib/BLI_allocator.hh
+++ b/source/blender/blenlib/BLI_allocator.hh
@@ -79,19 +79,20 @@ class RawAllocator {
public:
void *allocate(size_t size, size_t alignment, const char *UNUSED(name))
{
- BLI_assert(is_power_of_2_i((int)alignment));
+ BLI_assert(is_power_of_2_i(static_cast<int>(alignment)));
void *ptr = malloc(size + alignment + sizeof(MemHead));
- void *used_ptr = (void *)((uintptr_t)POINTER_OFFSET(ptr, alignment + sizeof(MemHead)) &
- ~((uintptr_t)alignment - 1));
- int offset = (int)((intptr_t)used_ptr - (intptr_t)ptr);
- BLI_assert(offset >= (int)sizeof(MemHead));
- ((MemHead *)used_ptr - 1)->offset = (int)offset;
+ void *used_ptr = reinterpret_cast<void *>(
+ reinterpret_cast<uintptr_t>(POINTER_OFFSET(ptr, alignment + sizeof(MemHead))) &
+ ~(static_cast<uintptr_t>(alignment) - 1));
+ int offset = static_cast<int>((intptr_t)used_ptr - (intptr_t)ptr);
+ BLI_assert(offset >= static_cast<int>(sizeof(MemHead)));
+ (static_cast<MemHead *>(used_ptr) - 1)->offset = offset;
return used_ptr;
}
void deallocate(void *ptr)
{
- MemHead *head = (MemHead *)ptr - 1;
+ MemHead *head = static_cast<MemHead *>(ptr) - 1;
int offset = -head->offset;
void *actual_pointer = POINTER_OFFSET(ptr, offset);
free(actual_pointer);
diff --git a/source/blender/blenlib/BLI_array.hh b/source/blender/blenlib/BLI_array.hh
index 796123af765..9b307dc6a04 100644
--- a/source/blender/blenlib/BLI_array.hh
+++ b/source/blender/blenlib/BLI_array.hh
@@ -176,7 +176,7 @@ class Array {
{
destruct_n(data_, size_);
if (!this->uses_inline_buffer()) {
- allocator_.deallocate((void *)data_);
+ allocator_.deallocate(static_cast<void *>(data_));
}
}
@@ -351,7 +351,8 @@ class Array {
T *allocate(int64_t size)
{
- return (T *)allocator_.allocate((size_t)size * sizeof(T), alignof(T), AT);
+ return static_cast<T *>(
+ allocator_.allocate(static_cast<size_t>(size) * sizeof(T), alignof(T), AT));
}
bool uses_inline_buffer() const
diff --git a/source/blender/blenlib/BLI_color.hh b/source/blender/blenlib/BLI_color.hh
index c0d2f43645d..e57a5109a66 100644
--- a/source/blender/blenlib/BLI_color.hh
+++ b/source/blender/blenlib/BLI_color.hh
@@ -63,10 +63,10 @@ struct Color4f {
uint64_t hash() const
{
- uint64_t x1 = *(uint32_t *)&r;
- uint64_t x2 = *(uint32_t *)&g;
- uint64_t x3 = *(uint32_t *)&b;
- uint64_t x4 = *(uint32_t *)&a;
+ uint64_t x1 = *reinterpret_cast<const uint32_t *>(&r);
+ uint64_t x2 = *reinterpret_cast<const uint32_t *>(&g);
+ uint64_t x3 = *reinterpret_cast<const uint32_t *>(&b);
+ uint64_t x4 = *reinterpret_cast<const uint32_t *>(&a);
return (x1 * 1283591) ^ (x2 * 850177) ^ (x3 * 735391) ^ (x4 * 442319);
}
};
@@ -120,8 +120,8 @@ struct Color4b {
uint64_t hash() const
{
- return ((uint64_t)r * 1283591) ^ ((uint64_t)g * 850177) ^ ((uint64_t)b * 735391) ^
- ((uint64_t)a * 442319);
+ return static_cast<uint64_t>(r * 1283591) ^ static_cast<uint64_t>(g * 850177) ^
+ static_cast<uint64_t>(b * 735391) ^ static_cast<uint64_t>(a * 442319);
}
};
diff --git a/source/blender/blenlib/BLI_float3.hh b/source/blender/blenlib/BLI_float3.hh
index a976e909738..2d90498fee8 100644
--- a/source/blender/blenlib/BLI_float3.hh
+++ b/source/blender/blenlib/BLI_float3.hh
@@ -31,7 +31,7 @@ struct float3 {
{
}
- float3(const float (*ptr)[3]) : float3((const float *)ptr)
+ float3(const float (*ptr)[3]) : float3(static_cast<const float *>(ptr[0]))
{
}
@@ -204,9 +204,9 @@ struct float3 {
uint64_t hash() const
{
- uint64_t x1 = *(uint32_t *)&x;
- uint64_t x2 = *(uint32_t *)&y;
- uint64_t x3 = *(uint32_t *)&z;
+ uint64_t x1 = *reinterpret_cast<const uint32_t *>(&x);
+ uint64_t x2 = *reinterpret_cast<const uint32_t *>(&y);
+ uint64_t x3 = *reinterpret_cast<const uint32_t *>(&z);
return (x1 * 435109) ^ (x2 * 380867) ^ (x3 * 1059217);
}
diff --git a/source/blender/blenlib/BLI_float4x4.hh b/source/blender/blenlib/BLI_float4x4.hh
index 85d38149bb9..0433197b22a 100644
--- a/source/blender/blenlib/BLI_float4x4.hh
+++ b/source/blender/blenlib/BLI_float4x4.hh
@@ -31,18 +31,18 @@ struct float4x4 {
memcpy(values, matrix, sizeof(float) * 16);
}
- float4x4(const float matrix[4][4]) : float4x4((float *)matrix)
+ float4x4(const float matrix[4][4]) : float4x4(static_cast<const float *>(matrix[0]))
{
}
operator float *()
{
- return (float *)this;
+ return &values[0][0];
}
operator const float *() const
{
- return (const float *)this;
+ return &values[0][0];
}
friend float4x4 operator*(const float4x4 &a, const float4x4 &b)
@@ -124,8 +124,8 @@ struct float4x4 {
{
uint64_t h = 435109;
for (int i = 0; i < 16; i++) {
- float value = ((const float *)this)[i];
- h = h * 33 + (*(uint32_t *)&value);
+ float value = (static_cast<const float *>(values[0]))[i];
+ h = h * 33 + *reinterpret_cast<const uint32_t *>(&value);
}
return h;
}
diff --git a/source/blender/blenlib/BLI_hash.hh b/source/blender/blenlib/BLI_hash.hh
index ad3224e037a..8301dbb8e3a 100644
--- a/source/blender/blenlib/BLI_hash.hh
+++ b/source/blender/blenlib/BLI_hash.hh
@@ -110,7 +110,7 @@ template<typename T> struct DefaultHash<const T> {
template<> struct DefaultHash<TYPE> { \
uint64_t operator()(TYPE value) const \
{ \
- return (uint64_t)value; \
+ return static_cast<uint64_t>(value); \
} \
}
@@ -135,14 +135,14 @@ TRIVIAL_DEFAULT_INT_HASH(uint64_t);
template<> struct DefaultHash<float> {
uint64_t operator()(float value) const
{
- return *(uint32_t *)&value;
+ return *reinterpret_cast<uint32_t *>(&value);
}
};
template<> struct DefaultHash<bool> {
uint64_t operator()(bool value) const
{
- return (uint64_t)(value != false) * 1298191;
+ return static_cast<uint64_t>((value != false) * 1298191);
}
};
@@ -186,8 +186,8 @@ template<> struct DefaultHash<StringRefNull> {
template<typename T> struct DefaultHash<T *> {
uint64_t operator()(const T *value) const
{
- uintptr_t ptr = (uintptr_t)value;
- uint64_t hash = (uint64_t)(ptr >> 4);
+ uintptr_t ptr = reinterpret_cast<uintptr_t>(value);
+ uint64_t hash = static_cast<uint64_t>(ptr >> 4);
return hash;
}
};
diff --git a/source/blender/blenlib/BLI_hash_tables.hh b/source/blender/blenlib/BLI_hash_tables.hh
index e6026d93e2c..9fc8ff30f79 100644
--- a/source/blender/blenlib/BLI_hash_tables.hh
+++ b/source/blender/blenlib/BLI_hash_tables.hh
@@ -56,7 +56,8 @@ inline constexpr int64_t log2_floor_constexpr(const int64_t x)
inline constexpr int64_t log2_ceil_constexpr(const int64_t x)
{
BLI_assert(x >= 0);
- return (is_power_of_2_constexpr((int)x)) ? log2_floor_constexpr(x) : log2_floor_constexpr(x) + 1;
+ return (is_power_of_2_constexpr(static_cast<int>(x))) ? log2_floor_constexpr(x) :
+ log2_floor_constexpr(x) + 1;
}
inline constexpr int64_t power_of_2_max_constexpr(const int64_t x)
@@ -83,14 +84,17 @@ inline constexpr int64_t ceil_division_by_fraction(const int64_t x,
const int64_t numerator,
const int64_t denominator)
{
- return (int64_t)ceil_division((uint64_t)x * (uint64_t)denominator, (uint64_t)numerator);
+ return static_cast<int64_t>(
+ ceil_division(static_cast<uint64_t>(x) * static_cast<uint64_t>(denominator),
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list