Browse Source

HashMap & HashSet: use existed IsPowerOfTwo() function

1vanK 3 years ago
parent
commit
dba686302c
2 changed files with 5 additions and 10 deletions
  1. 3 5
      Source/Urho3D/Container/HashMap.h
  2. 2 5
      Source/Urho3D/Container/HashSet.h

+ 3 - 5
Source/Urho3D/Container/HashMap.h

@@ -7,6 +7,7 @@
 #include "../Container/Pair.h"
 #include "../Container/Sort.h"
 #include "../Container/Vector.h"
+#include "../Math/MathDefs.h"
 
 #include <cassert>
 #include <initializer_list>
@@ -491,14 +492,11 @@ public:
     {
         if (numBuckets == NumBuckets())
             return true;
+        
         if (!numBuckets || numBuckets < Size() / MAX_LOAD_FACTOR)
             return false;
 
-        // Check for being power of two
-        unsigned check = numBuckets;
-        while (!(check & 1u))
-            check >>= 1;
-        if (check != 1)
+        if (!IsPowerOfTwo(numBuckets))
             return false;
 
         AllocateBuckets(Size(), numBuckets);

+ 2 - 5
Source/Urho3D/Container/HashSet.h

@@ -5,6 +5,7 @@
 
 #include "../Container/HashBase.h"
 #include "../Container/Sort.h"
+#include "../Math/MathDefs.h"
 
 #include <cassert>
 #include <initializer_list>
@@ -427,11 +428,7 @@ public:
         if (!numBuckets || numBuckets < Size() / MAX_LOAD_FACTOR)
             return false;
 
-        // Check for being power of two
-        unsigned check = numBuckets;
-        while (!(check & 1u))
-            check >>= 1;
-        if (check != 1)
+        if (!IsPowerOfTwo(numBuckets))
             return false;
 
         AllocateBuckets(Size(), numBuckets);