[Bf-blender-cvs] [af898490672] functions: replace magic number

Jacques Lucke noreply at git.blender.org
Fri Aug 23 17:35:37 CEST 2019


Commit: af898490672b1a87d24a197ff8d0a64acb7e4822
Author: Jacques Lucke
Date:   Fri Aug 23 16:04:21 2019 +0200
Branches: functions
https://developer.blender.org/rBaf898490672b1a87d24a197ff8d0a64acb7e4822

replace magic number

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

M	source/blender/blenlib/BLI_map.hpp
M	source/blender/blenlib/BLI_set.hpp
M	source/blender/blenlib/BLI_string_map.hpp

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

diff --git a/source/blender/blenlib/BLI_map.hpp b/source/blender/blenlib/BLI_map.hpp
index c7d2a0ef581..79af0146282 100644
--- a/source/blender/blenlib/BLI_map.hpp
+++ b/source/blender/blenlib/BLI_map.hpp
@@ -37,7 +37,7 @@ namespace BLI {
   uint32_t hash = MyHash<KeyT>{}(KEY); \
   uint32_t perturb = hash; \
   while (true) { \
-    uint32_t item_index = (hash & ARRAY.slot_mask()) >> 2; \
+    uint32_t item_index = (hash & ARRAY.slot_mask()) >> OFFSET_SHIFT; \
     uint8_t R_OFFSET = hash & OFFSET_MASK; \
     uint8_t initial_offset = R_OFFSET; \
     OPTIONAL_CONST Item &R_ITEM = ARRAY.item(item_index); \
@@ -55,6 +55,7 @@ namespace BLI {
 template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator> class Map {
  private:
   static constexpr uint32_t OFFSET_MASK = 3;
+  static constexpr uint32_t OFFSET_SHIFT = 2;
 
   class Item {
    private:
@@ -454,7 +455,7 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
 
     const KeyT &operator*() const
     {
-      uint32_t item_index = this->m_slot >> 2;
+      uint32_t item_index = this->m_slot >> OFFSET_SHIFT;
       uint32_t offset = this->m_slot & OFFSET_MASK;
       const Item &item = this->m_map->m_array.item(item_index);
       BLI_assert(item.is_set(offset));
@@ -470,7 +471,7 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
 
     ValueT &operator*() const
     {
-      uint32_t item_index = this->m_slot >> 2;
+      uint32_t item_index = this->m_slot >> OFFSET_SHIFT;
       uint32_t offset = this->m_slot & OFFSET_MASK;
       const Item &item = this->m_map->m_array.item(item_index);
       BLI_assert(item.is_set(offset));
@@ -497,7 +498,7 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
 
     UserItem operator*() const
     {
-      uint32_t item_index = this->m_slot >> 2;
+      uint32_t item_index = this->m_slot >> OFFSET_SHIFT;
       uint32_t offset = this->m_slot & OFFSET_MASK;
       const Item &item = this->m_map->m_array.item(item_index);
       BLI_assert(item.is_set(offset));
@@ -536,7 +537,7 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
   uint32_t next_slot(uint32_t slot) const
   {
     for (; slot < m_array.slots_total(); slot++) {
-      uint32_t item_index = slot >> 2;
+      uint32_t item_index = slot >> OFFSET_SHIFT;
       uint32_t offset = slot & OFFSET_MASK;
       const Item &item = m_array.item(item_index);
       if (item.is_set(offset)) {
diff --git a/source/blender/blenlib/BLI_set.hpp b/source/blender/blenlib/BLI_set.hpp
index 9920b058f61..2142ba3235d 100644
--- a/source/blender/blenlib/BLI_set.hpp
+++ b/source/blender/blenlib/BLI_set.hpp
@@ -12,7 +12,7 @@ namespace BLI {
   uint32_t hash = MyHash<T>{}(VALUE); \
   uint32_t perturb = hash; \
   while (true) { \
-    uint32_t item_index = (hash & ARRAY.slot_mask()) >> 2; \
+    uint32_t item_index = (hash & ARRAY.slot_mask()) >> OFFSET_SHIFT; \
     uint8_t R_OFFSET = hash & OFFSET_MASK; \
     uint8_t initial_offset = R_OFFSET; \
     OPTIONAL_CONST Item &R_ITEM = ARRAY.item(item_index); \
@@ -30,6 +30,7 @@ namespace BLI {
 template<typename T, typename Allocator = GuardedAllocator> class Set {
  private:
   static constexpr uint32_t OFFSET_MASK = 3;
+  static constexpr uint32_t OFFSET_SHIFT = 2;
 
   class Item {
    private:
@@ -310,7 +311,7 @@ template<typename T, typename Allocator = GuardedAllocator> class Set {
 
     const T &operator*() const
     {
-      uint32_t item_index = m_slot >> 2;
+      uint32_t item_index = m_slot >> OFFSET_SHIFT;
       uint32_t offset = m_slot & OFFSET_MASK;
       const Item &item = m_set->m_array.item(item_index);
       BLI_assert(item.is_set(offset));
@@ -345,7 +346,7 @@ template<typename T, typename Allocator = GuardedAllocator> class Set {
   uint32_t next_slot(uint32_t slot) const
   {
     for (; slot < m_array.slots_total(); slot++) {
-      uint32_t item_index = slot >> 2;
+      uint32_t item_index = slot >> OFFSET_SHIFT;
       uint32_t offset = slot & OFFSET_MASK;
       const Item &item = m_array.item(item_index);
       if (item.is_set(offset)) {
diff --git a/source/blender/blenlib/BLI_string_map.hpp b/source/blender/blenlib/BLI_string_map.hpp
index d65612878ec..596e63ca42e 100644
--- a/source/blender/blenlib/BLI_string_map.hpp
+++ b/source/blender/blenlib/BLI_string_map.hpp
@@ -38,7 +38,7 @@ namespace BLI {
   uint32_t hash_copy = HASH; \
   uint32_t perturb = HASH; \
   while (true) { \
-    uint32_t item_index = (hash_copy & ARRAY.slot_mask()) >> 2; \
+    uint32_t item_index = (hash_copy & ARRAY.slot_mask()) >> OFFSET_SHIFT; \
     uint8_t R_OFFSET = hash_copy & OFFSET_MASK; \
     uint8_t initial_offset = R_OFFSET; \
     OPTIONAL_CONST Item &R_ITEM = ARRAY.item(item_index); \
@@ -56,6 +56,7 @@ namespace BLI {
 template<typename T, typename Allocator = GuardedAllocator> class StringMap {
  private:
   static constexpr uint32_t OFFSET_MASK = 3;
+  static constexpr uint32_t OFFSET_SHIFT = 2;
 
   class Item {
    private:



More information about the Bf-blender-cvs mailing list