Bug 924392 - part 1 - don't use JS_BITS_PER_WORD for bit arrays; r=Waldo
authorNathan Froyd <froydnj@mozilla.com>
Tue, 08 Oct 2013 10:04:06 -0400
changeset 150193 a53db57e615e5126efe2bbc3bb8005f074e3300d
parent 150192 0fc34ab639b968090f53815c69724793b29a2ed4
child 150194 43277bc87c17c20ddf6426317c59cce6ce1bd0e2
push id34775
push usernfroyd@mozilla.com
push dateWed, 09 Oct 2013 12:30:56 +0000
treeherdermozilla-inbound@bfbd94299127 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs924392
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 924392 - part 1 - don't use JS_BITS_PER_WORD for bit arrays; r=Waldo
js/src/jsutil.h
--- a/js/src/jsutil.h
+++ b/js/src/jsutil.h
@@ -9,16 +9,18 @@
  */
 
 #ifndef jsutil_h
 #define jsutil_h
 
 #include "mozilla/Compiler.h"
 #include "mozilla/GuardObjects.h"
 
+#include <limits.h>
+
 #ifdef USE_ZLIB
 #include <zlib.h>
 #endif
 
 #include "js/Utility.h"
 
 static JS_ALWAYS_INLINE void *
 js_memcpy(void *dst_, const void *src_, size_t len)
@@ -199,34 +201,36 @@ UnsignedPtrDiff(const void *bigger, cons
 {
     return size_t(bigger) - size_t(smaller);
 }
 
 /*****************************************************************************/
 
 /* A bit array is an array of bits represented by an array of words (size_t). */
 
+static const size_t BitArrayElementBits = sizeof(size_t) * CHAR_BIT;
+
 static inline unsigned
 NumWordsForBitArrayOfLength(size_t length)
 {
-    return (length + (JS_BITS_PER_WORD - 1)) / JS_BITS_PER_WORD;
+    return (length + (BitArrayElementBits - 1)) / BitArrayElementBits;
 }
 
 static inline unsigned
 BitArrayIndexToWordIndex(size_t length, size_t bitIndex)
 {
-    unsigned wordIndex = bitIndex / JS_BITS_PER_WORD;
+    unsigned wordIndex = bitIndex / BitArrayElementBits;
     JS_ASSERT(wordIndex < length);
     return wordIndex;
 }
 
 static inline size_t
 BitArrayIndexToWordMask(size_t i)
 {
-    return size_t(1) << (i % JS_BITS_PER_WORD);
+    return size_t(1) << (i % BitArrayElementBits);
 }
 
 static inline bool
 IsBitArrayElementSet(size_t *array, size_t length, size_t i)
 {
     return array[BitArrayIndexToWordIndex(length, i)] & BitArrayIndexToWordMask(i);
 }