[Bf-blender-cvs] [ef8cbccd54d] functions: simplify method names

Jacques Lucke noreply at git.blender.org
Mon Jul 8 17:56:39 CEST 2019


Commit: ef8cbccd54d57e79cbfbefdbe7197f2be1490ee3
Author: Jacques Lucke
Date:   Mon Jul 8 11:03:26 2019 +0200
Branches: functions
https://developer.blender.org/rBef8cbccd54d57e79cbfbefdbe7197f2be1490ee3

simplify method names

===================================================================

M	source/blender/blenlib/BLI_fixed_array_allocator.hpp
M	source/blender/simulations/bparticles/attributes.cpp
M	source/blender/simulations/bparticles/simulate.cpp
M	tests/gtests/blenlib/BLI_fixed_array_allocator_test.cc

===================================================================

diff --git a/source/blender/blenlib/BLI_fixed_array_allocator.hpp b/source/blender/blenlib/BLI_fixed_array_allocator.hpp
index a1471f44840..1c7ec0c2ded 100644
--- a/source/blender/blenlib/BLI_fixed_array_allocator.hpp
+++ b/source/blender/blenlib/BLI_fixed_array_allocator.hpp
@@ -35,7 +35,7 @@ class FixedArrayAllocator {
     return m_array_length;
   }
 
-  void *allocate_array(uint element_size)
+  void *allocate(uint element_size)
   {
     SmallStack<void *> &stack = this->stack_for_element_size(element_size);
     if (stack.size() > 0) {
@@ -46,20 +46,20 @@ class FixedArrayAllocator {
     return ptr;
   }
 
-  void deallocate_array(void *ptr, uint element_size)
+  void deallocate(void *ptr, uint element_size)
   {
     SmallStack<void *> &stack = this->stack_for_element_size(element_size);
     stack.push(ptr);
   }
 
-  template<typename T> T *allocate_array()
+  template<typename T> T *allocate()
   {
-    return (T *)this->allocate_array(sizeof(T));
+    return (T *)this->allocate(sizeof(T));
   }
 
-  template<typename T> void deallocate_array(T *ptr)
+  template<typename T> void deallocate(T *ptr)
   {
-    return this->deallocate_array(ptr, sizeof(T));
+    return this->deallocate(ptr, sizeof(T));
   }
 
   template<typename T> class ScopedAllocation {
@@ -92,7 +92,7 @@ class FixedArrayAllocator {
     ~ScopedAllocation()
     {
       if (m_ptr != nullptr) {
-        m_allocator.deallocate_array(m_ptr, m_element_size);
+        m_allocator.deallocate(m_ptr, m_element_size);
       }
     }
 
@@ -102,14 +102,14 @@ class FixedArrayAllocator {
     }
   };
 
-  ScopedAllocation<void> allocate_array_scoped(uint element_size)
+  ScopedAllocation<void> allocate_scoped(uint element_size)
   {
-    return ScopedAllocation<void>(*this, this->allocate_array(element_size), element_size);
+    return ScopedAllocation<void>(*this, this->allocate(element_size), element_size);
   }
 
-  template<typename T> ScopedAllocation<T> allocate_array_scoped()
+  template<typename T> ScopedAllocation<T> allocate_scoped()
   {
-    return ScopedAllocation<T>(*this, this->allocate_array<T>(), sizeof(T));
+    return ScopedAllocation<T>(*this, this->allocate<T>(), sizeof(T));
   }
 
  private:
diff --git a/source/blender/simulations/bparticles/attributes.cpp b/source/blender/simulations/bparticles/attributes.cpp
index bec1e08be18..35c93191a4f 100644
--- a/source/blender/simulations/bparticles/attributes.cpp
+++ b/source/blender/simulations/bparticles/attributes.cpp
@@ -53,7 +53,7 @@ AttributeArraysCore AttributeArraysCore::NewWithArrayAllocator(AttributesInfo &i
   SmallVector<void *> arrays;
   for (AttributeType type : info.types()) {
     uint element_size = size_of_attribute_type(type);
-    void *ptr = allocator.allocate_array(element_size);
+    void *ptr = allocator.allocate(element_size);
     arrays.append(ptr);
   }
   return AttributeArraysCore(info, arrays, allocator.array_size());
@@ -71,7 +71,7 @@ void AttributeArraysCore::deallocate_in_array_allocator(FixedArrayAllocator &all
   for (uint i = 0; i < m_arrays.size(); i++) {
     void *ptr = m_arrays[i];
     uint element_size = size_of_attribute_type(m_info->type_of(i));
-    allocator.deallocate_array(ptr, element_size);
+    allocator.deallocate(ptr, element_size);
   }
 }
 
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 46dea387b7b..a5e3bc33f3b 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -234,10 +234,10 @@ BLI_NOINLINE static void simulate_to_next_event(FixedArrayAllocator &array_alloc
   uint amount = particles.size();
 
   BLI_assert(array_allocator.array_size() >= amount);
-  auto next_event_indices_array = array_allocator.allocate_array_scoped<int>();
-  auto time_factors_to_next_event_array = array_allocator.allocate_array_scoped<float>();
-  auto indices_with_event_array = array_allocator.allocate_array_scoped<uint>();
-  auto particle_indices_with_event_array = array_allocator.allocate_array_scoped<uint>();
+  auto next_event_indices_array = array_allocator.allocate_scoped<int>();
+  auto time_factors_to_next_event_array = array_allocator.allocate_scoped<float>();
+  auto indices_with_event_array = array_allocator.allocate_scoped<uint>();
+  auto particle_indices_with_event_array = array_allocator.allocate_scoped<uint>();
 
   VectorAdaptor<int> next_event_indices(next_event_indices_array, amount, amount);
   VectorAdaptor<float> time_factors_to_next_event(
@@ -246,7 +246,7 @@ BLI_NOINLINE static void simulate_to_next_event(FixedArrayAllocator &array_alloc
   VectorAdaptor<uint> particle_indices_with_event(particle_indices_with_event_array, amount);
 
   uint max_event_storage_size = std::max(get_max_event_storage_size(events), 1u);
-  auto event_storage_array = array_allocator.allocate_array_scoped(max_event_storage_size);
+  auto event_storage_array = array_allocator.allocate_scoped(max_event_storage_size);
   EventStorage event_storage(event_storage_array, max_event_storage_size);
 
   find_next_event_per_particle(particles,
@@ -309,10 +309,10 @@ BLI_NOINLINE static void simulate_with_max_n_events(
     VectorAdaptor<uint> &r_unfinished_particle_indices)
 {
   BLI_assert(array_allocator.array_size() >= block.active_amount());
-  auto indices_A = array_allocator.allocate_array_scoped<uint>();
-  auto indices_B = array_allocator.allocate_array_scoped<uint>();
-  auto durations_A = array_allocator.allocate_array_scoped<float>();
-  auto durations_B = array_allocator.allocate_array_scoped<float>();
+  auto indices_A = array_allocator.allocate_scoped<uint>();
+  auto indices_B = array_allocator.allocate_scoped<uint>();
+  auto durations_A = array_allocator.allocate_scoped<float>();
+  auto durations_B = array_allocator.allocate_scoped<float>();
 
   /* Handle first event separately to be able to use the static number range. */
   uint amount_left = block.active_amount();
@@ -434,7 +434,7 @@ BLI_NOINLINE static void simulate_block(FixedArrayAllocator &array_allocator,
     apply_remaining_offsets(all_particles_in_block, attribute_offsets);
   }
   else {
-    uint *indices_array = array_allocator.allocate_array<uint>();
+    auto indices_array = array_allocator.allocate_scoped<uint>();
     VectorAdaptor<uint> unfinished_particle_indices(indices_array, amount);
 
     simulate_with_max_n_events(10,
@@ -452,8 +452,6 @@ BLI_NOINLINE static void simulate_block(FixedArrayAllocator &array_allocator,
       ParticleSet remaining_particles(block, unfinished_particle_indices);
       apply_remaining_offsets(remaining_particles, attribute_offsets);
     }
-
-    array_allocator.deallocate_array(indices_array);
   }
 
   attribute_offsets_core.deallocate_in_array_allocator(array_allocator);
diff --git a/tests/gtests/blenlib/BLI_fixed_array_allocator_test.cc b/tests/gtests/blenlib/BLI_fixed_array_allocator_test.cc
index 67648f083f8..dd814cd54ad 100644
--- a/tests/gtests/blenlib/BLI_fixed_array_allocator_test.cc
+++ b/tests/gtests/blenlib/BLI_fixed_array_allocator_test.cc
@@ -6,24 +6,24 @@ using BLI::FixedArrayAllocator;
 TEST(fixed_array_allocator, AllocateSameSize)
 {
   FixedArrayAllocator allocator(42);
-  void *ptr1 = allocator.allocate_array(4);
-  void *ptr2 = allocator.allocate_array(4);
+  void *ptr1 = allocator.allocate(4);
+  void *ptr2 = allocator.allocate(4);
   EXPECT_NE(ptr1, ptr2);
 }
 
 TEST(fixed_array_allocator, AllocateDifferentSizes)
 {
   FixedArrayAllocator allocator(42);
-  void *ptr1 = allocator.allocate_array(3);
-  void *ptr2 = allocator.allocate_array(4);
+  void *ptr1 = allocator.allocate(3);
+  void *ptr2 = allocator.allocate(4);
   EXPECT_NE(ptr1, ptr2);
 }
 
 TEST(fixed_array_allocator, AllocateSamePointerTwice)
 {
   FixedArrayAllocator allocator(42);
-  void *ptr1 = allocator.allocate_array(10);
-  allocator.deallocate_array(ptr1, 10);
-  void *ptr2 = allocator.allocate_array(10);
+  void *ptr1 = allocator.allocate(10);
+  allocator.deallocate(ptr1, 10);
+  void *ptr2 = allocator.allocate(10);
   EXPECT_EQ(ptr1, ptr2);
 }



More information about the Bf-blender-cvs mailing list