Title: [140186] trunk/Source
Revision
140186
Author
msab...@apple.com
Date
2013-01-18 11:16:26 -0800 (Fri, 18 Jan 2013)

Log Message

Refactor isPowerOf2() and add getLSBSet()
https://bugs.webkit.org/show_bug.cgi?id=107306

Reviewed by Filip Pizlo.

Source/_javascript_Core: 

Moved implementation of isPowerOf2() to new hasOneBitSet() in wtf/MathExtras.h.

* runtime/PropertyMapHashTable.h:
(JSC::isPowerOf2):

Source/WTF: 

Moved runtime/PropertyMapHashTable.h:PowerOf2() to new hasOneBitSet() and added getLSBSet().

* wtf/MathExtras.h:
(hasOneBitSet):
(getLSBSet):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (140185 => 140186)


--- trunk/Source/_javascript_Core/ChangeLog	2013-01-18 19:14:32 UTC (rev 140185)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-01-18 19:16:26 UTC (rev 140186)
@@ -1,3 +1,15 @@
+2013-01-18  Michael Saboff  <msab...@apple.com>
+
+        Refactor isPowerOf2() and add getLSBSet()
+        https://bugs.webkit.org/show_bug.cgi?id=107306
+
+        Reviewed by Filip Pizlo.
+
+        Moved implementation of isPowerOf2() to new hasOneBitSet() in wtf/MathExtras.h.
+
+        * runtime/PropertyMapHashTable.h:
+        (JSC::isPowerOf2):
+
 2013-01-17  Mark Hahnenberg  <mhahnenb...@apple.com>
 
         Objective-C API: Clean up JSValue.mm

Modified: trunk/Source/_javascript_Core/runtime/PropertyMapHashTable.h (140185 => 140186)


--- trunk/Source/_javascript_Core/runtime/PropertyMapHashTable.h	2013-01-18 19:14:32 UTC (rev 140185)
+++ trunk/Source/_javascript_Core/runtime/PropertyMapHashTable.h	2013-01-18 19:16:26 UTC (rev 140186)
@@ -24,6 +24,7 @@
 #include "PropertyOffset.h"
 #include "WriteBarrier.h"
 #include <wtf/HashTable.h>
+#include <wtf/MathExtras.h>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/Vector.h>
 #include <wtf/text/StringImpl.h>
@@ -50,9 +51,7 @@
 
 inline bool isPowerOf2(unsigned v)
 {
-    // Taken from http://www.cs.utk.edu/~vose/c-stuff/bithacks.html
-    
-    return !(v & (v - 1)) && v;
+    return hasOneBitSet(v);
 }
 
 inline unsigned nextPowerOf2(unsigned v)

Modified: trunk/Source/WTF/ChangeLog (140185 => 140186)


--- trunk/Source/WTF/ChangeLog	2013-01-18 19:14:32 UTC (rev 140185)
+++ trunk/Source/WTF/ChangeLog	2013-01-18 19:16:26 UTC (rev 140186)
@@ -1,3 +1,16 @@
+2013-01-18  Michael Saboff  <msab...@apple.com>
+
+        Refactor isPowerOf2() and add getLSBSet()
+        https://bugs.webkit.org/show_bug.cgi?id=107306
+
+        Reviewed by Filip Pizlo.
+
+        Moved runtime/PropertyMapHashTable.h:PowerOf2() to new hasOneBitSet() and added getLSBSet().
+
+        * wtf/MathExtras.h:
+        (hasOneBitSet):
+        (getLSBSet):
+
 2013-01-18  David Kilzer  <ddkil...@apple.com>
 
         Fix WTF::copyLCharsFromUCharSource() to compile with -Wshorten-64-to-32

Modified: trunk/Source/WTF/wtf/MathExtras.h (140185 => 140186)


--- trunk/Source/WTF/wtf/MathExtras.h	2013-01-18 19:14:32 UTC (rev 140185)
+++ trunk/Source/WTF/wtf/MathExtras.h	2013-01-18 19:16:26 UTC (rev 140186)
@@ -294,6 +294,11 @@
     return x > static_cast<float>(std::numeric_limits<int>::min()) && x < static_cast<float>(std::numeric_limits<int>::max());
 }
 
+template<typename T> inline bool hasOneBitSet(T value)
+{
+    return !((value - 1) & value) && value;
+}
+
 template<typename T> inline bool hasZeroOrOneBitsSet(T value)
 {
     return !((value - 1) & value);
@@ -304,6 +309,16 @@
     return !hasZeroOrOneBitsSet(value);
 }
 
+template <typename T> inline unsigned getLSBSet(T value)
+{
+    unsigned result = 0;
+
+    while (value >>= 1)
+        ++result;
+
+    return result;
+}
+
 template<typename T> inline T timesThreePlusOneDividedByTwo(T value)
 {
     // Mathematically equivalent to:
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to