[Bf-blender-cvs] [93da09d717f] master: Cleanup: add const in various places

Jacques Lucke noreply at git.blender.org
Fri Jul 3 14:53:26 CEST 2020


Commit: 93da09d717ff4502975c506c574faf0c07f010b4
Author: Jacques Lucke
Date:   Fri Jul 3 14:52:51 2020 +0200
Branches: master
https://developer.blender.org/rB93da09d717ff4502975c506c574faf0c07f010b4

Cleanup: add const in various places

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

M	source/blender/blenlib/BLI_hash_tables.hh
M	source/blender/blenlib/BLI_linear_allocator.hh
M	source/blender/blenlib/BLI_probing_strategies.hh
M	source/blender/blenlib/BLI_set.hh
M	source/blender/blenlib/BLI_set_slots.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_timeit.hh
M	source/blender/blenlib/BLI_vector.hh
M	source/blender/blenlib/BLI_vector_set.hh

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

diff --git a/source/blender/blenlib/BLI_hash_tables.hh b/source/blender/blenlib/BLI_hash_tables.hh
index 51818ecada6..5f9e06c5a64 100644
--- a/source/blender/blenlib/BLI_hash_tables.hh
+++ b/source/blender/blenlib/BLI_hash_tables.hh
@@ -42,56 +42,57 @@ namespace blender {
  * Those should eventually be de-duplicated with functions in BLI_math_base.h.
  * \{ */
 
-inline constexpr int is_power_of_2_i_constexpr(int n)
+inline constexpr int is_power_of_2_i_constexpr(const int n)
 {
   return (n & (n - 1)) == 0;
 }
 
-inline constexpr uint32_t log2_floor_u_constexpr(uint32_t x)
+inline constexpr uint32_t log2_floor_u_constexpr(const uint32_t x)
 {
   return x <= 1 ? 0 : 1 + log2_floor_u_constexpr(x >> 1);
 }
 
-inline constexpr uint32_t log2_ceil_u_constexpr(uint32_t x)
+inline constexpr uint32_t log2_ceil_u_constexpr(const uint32_t x)
 {
   return (is_power_of_2_i_constexpr((int)x)) ? log2_floor_u_constexpr(x) :
                                                log2_floor_u_constexpr(x) + 1;
 }
 
-inline constexpr uint32_t power_of_2_max_u_constexpr(uint32_t x)
+inline constexpr uint32_t power_of_2_max_u_constexpr(const uint32_t x)
 {
   return 1u << log2_ceil_u_constexpr(x);
 }
 
-template<typename IntT> inline constexpr IntT ceil_division(IntT x, IntT y)
+template<typename IntT> inline constexpr IntT ceil_division(const IntT x, const IntT y)
 {
   BLI_STATIC_ASSERT(!std::is_signed<IntT>::value, "");
   return x / y + ((x % y) != 0);
 }
 
-template<typename IntT> inline constexpr IntT floor_division(IntT x, IntT y)
+template<typename IntT> inline constexpr IntT floor_division(const IntT x, const IntT y)
 {
   BLI_STATIC_ASSERT(!std::is_signed<IntT>::value, "");
   return x / y;
 }
 
-inline constexpr uint32_t ceil_division_by_fraction(uint32_t x,
-                                                    uint32_t numerator,
-                                                    uint32_t denominator)
+inline constexpr uint32_t ceil_division_by_fraction(const uint32_t x,
+                                                    const uint32_t numerator,
+                                                    const uint32_t denominator)
 {
   return (uint32_t)ceil_division((uint64_t)x * (uint64_t)denominator, (uint64_t)numerator);
 }
 
-inline constexpr uint32_t floor_multiplication_with_fraction(uint32_t x,
-                                                             uint32_t numerator,
-                                                             uint32_t denominator)
+inline constexpr uint32_t floor_multiplication_with_fraction(const uint32_t x,
+                                                             const uint32_t numerator,
+                                                             const uint32_t denominator)
 {
   return (uint32_t)((uint64_t)x * (uint64_t)numerator / (uint64_t)denominator);
 }
 
-inline constexpr uint32_t total_slot_amount_for_usable_slots(uint32_t min_usable_slots,
-                                                             uint32_t max_load_factor_numerator,
-                                                             uint32_t max_load_factor_denominator)
+inline constexpr uint32_t total_slot_amount_for_usable_slots(
+    const uint32_t min_usable_slots,
+    const uint32_t max_load_factor_numerator,
+    const uint32_t max_load_factor_denominator)
 {
   return power_of_2_max_u_constexpr(ceil_division_by_fraction(
       min_usable_slots, max_load_factor_numerator, max_load_factor_denominator));
@@ -129,7 +130,7 @@ class LoadFactor {
 
     uint32_t total_slots = this->compute_total_slots(min_usable_slots, numerator_, denominator_);
     total_slots = std::max(total_slots, min_total_slots);
-    uint32_t usable_slots = floor_multiplication_with_fraction(
+    const uint32_t usable_slots = floor_multiplication_with_fraction(
         total_slots, numerator_, denominator_);
     BLI_assert(min_usable_slots <= usable_slots);
 
diff --git a/source/blender/blenlib/BLI_linear_allocator.hh b/source/blender/blenlib/BLI_linear_allocator.hh
index 03264fef3bd..b13d88d5b93 100644
--- a/source/blender/blenlib/BLI_linear_allocator.hh
+++ b/source/blender/blenlib/BLI_linear_allocator.hh
@@ -66,7 +66,7 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
    *
    * The alignment has to be a power of 2.
    */
-  void *allocate(uint size, uint alignment)
+  void *allocate(const uint size, const uint alignment)
   {
     BLI_assert(alignment >= 1);
     BLI_assert(is_power_of_2_i(alignment));
@@ -75,9 +75,10 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
     debug_allocated_amount_ += size;
 #endif
 
-    uintptr_t alignment_mask = alignment - 1;
-    uintptr_t potential_allocation_begin = (current_begin_ + alignment_mask) & ~alignment_mask;
-    uintptr_t potential_allocation_end = potential_allocation_begin + size;
+    const uintptr_t alignment_mask = alignment - 1;
+    const uintptr_t potential_allocation_begin = (current_begin_ + alignment_mask) &
+                                                 ~alignment_mask;
+    const uintptr_t potential_allocation_end = potential_allocation_begin + size;
 
     if (potential_allocation_end <= current_end_) {
       current_begin_ = potential_allocation_end;
@@ -140,7 +141,7 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
    */
   StringRefNull copy_string(StringRef str)
   {
-    uint alloc_size = str.size() + 1;
+    const uint alloc_size = str.size() + 1;
     char *buffer = (char *)this->allocate(alloc_size, 1);
     str.copy(buffer, alloc_size);
     return StringRefNull((const char *)buffer);
@@ -205,7 +206,8 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
       }
     }
 
-    uint size_in_bytes = power_of_2_min_u(std::max(min_allocation_size, next_min_alloc_size_));
+    const uint size_in_bytes = power_of_2_min_u(
+        std::max(min_allocation_size, next_min_alloc_size_));
     next_min_alloc_size_ = size_in_bytes * 2;
 
     void *buffer = allocator_.allocate(size_in_bytes, 8, AT);
diff --git a/source/blender/blenlib/BLI_probing_strategies.hh b/source/blender/blenlib/BLI_probing_strategies.hh
index 3296ce9a968..d2b16ac3516 100644
--- a/source/blender/blenlib/BLI_probing_strategies.hh
+++ b/source/blender/blenlib/BLI_probing_strategies.hh
@@ -68,7 +68,7 @@ class LinearProbingStrategy {
   uint32_t hash_;
 
  public:
-  LinearProbingStrategy(uint32_t hash) : hash_(hash)
+  LinearProbingStrategy(const uint32_t hash) : hash_(hash)
   {
   }
 
@@ -106,7 +106,7 @@ class QuadraticProbingStrategy {
   uint32_t iteration_;
 
  public:
-  QuadraticProbingStrategy(uint32_t hash)
+  QuadraticProbingStrategy(const uint32_t hash)
       : original_hash_(hash), current_hash_(hash), iteration_(1)
   {
   }
@@ -144,7 +144,7 @@ template<uint32_t LinearSteps = 1, bool PreShuffle = false> class PythonProbingS
   uint32_t perturb_;
 
  public:
-  PythonProbingStrategy(uint32_t hash) : hash_(hash), perturb_(hash)
+  PythonProbingStrategy(const uint32_t hash) : hash_(hash), perturb_(hash)
   {
     if (PreShuffle) {
       this->next();
@@ -179,7 +179,7 @@ template<uint32_t LinearSteps = 2, bool PreShuffle = false> class ShuffleProbing
   uint32_t perturb_;
 
  public:
-  ShuffleProbingStrategy(uint32_t hash) : hash_(hash), perturb_(hash)
+  ShuffleProbingStrategy(const uint32_t hash) : hash_(hash), perturb_(hash)
   {
     if (PreShuffle) {
       this->next();
diff --git a/source/blender/blenlib/BLI_set.hh b/source/blender/blenlib/BLI_set.hh
index 86fea8f39e7..09b2d170eea 100644
--- a/source/blender/blenlib/BLI_set.hh
+++ b/source/blender/blenlib/BLI_set.hh
@@ -493,7 +493,7 @@ class Set {
    * Potentially resize the set such that it can hold the specified number of keys without another
    * grow operation.
    */
-  void reserve(uint32_t n)
+  void reserve(const uint32_t n)
   {
     if (usable_slots_ < n) {
       this->realloc_and_reinsert(n);
@@ -527,12 +527,12 @@ class Set {
   }
 
  private:
-  BLI_NOINLINE void realloc_and_reinsert(uint32_t min_usable_slots)
+  BLI_NOINLINE void realloc_and_reinsert(const uint32_t min_usable_slots)
   {
     uint32_t total_slots, usable_slots;
     max_load_factor_.compute_total_and_usable_slots(
         SlotArray::inline_buffer_capacity(), min_usable_slots, &total_slots, &usable_slots);
-    uint32_t new_slot_mask = total_slots - 1;
+    const uint32_t new_slot_mask = total_slots - 1;
 
     /**
      * Optimize the case when the set was empty beforehand. We can avoid some copies here.
@@ -568,9 +568,9 @@ class Set {
 
   void add_after_grow_and_destruct_old(Slot &old_slot,
                                        SlotArray &new_slots,
-                                       uint32_t new_slot_mask)
+                                       const uint32_t new_slot_mask)
   {
-    uint32_t hash = old_slot.get_hash(Hash());
+    const uint32_t hash = old_slot.get_hash(Hash());
 
     SLOT_PROBING_BEGIN (ProbingStrategy, hash, new_slot_mask, slot_index) {
       Slot &slot = new_slots[slot_index];
@@ -582,7 +582,8 @@ class Set {
     SLOT_PROBING_END();
   }
 
-  template<typename ForwardKey> bool contains__impl(const ForwardKey &key, uint32_t hash) const
+  template<typename ForwardKey>
+  bool contains__impl(const ForwardKey &key, const uint32_t hash) const
   {
     SET_SLOT_PROBING_BEGIN (hash, slot) {
       if (slot.is_empty()) {
@@ -595,7 +596,7 @@ class Set {
     SET_SLOT_PROBING_END();
   }
 
-  template<typename ForwardKey> void add_new__impl(ForwardKey &&key, uint32_t hash)
+  template<typename ForwardKey> void add_new__impl(ForwardKey &&key, const uint32_t hash)
   {
     BLI_assert(!this->contains_as(key));
 
@@ -611,7 +612,7 @@ class Set {
     SET_SLOT_PROBING_END();
   }
 
-  template<typename ForwardKey> bool add__impl(ForwardKey &&key, uint32_t hash)
+  template<typename ForwardKey> bool add__impl(ForwardKey &&key, const uint32_t hash)
   {
     this->ensure_can_add();
 
@@ -628,7 +629,7 @@ class Set {
     SET_SLOT_PROBING_END();
   }
 
-  template<typename ForwardKey> bool remove__impl(const ForwardKey &key, uint32_t hash)
+  template<typename ForwardKey> bool remove__impl(const ForwardKey &key, const uint32_t h

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list