Bug 950716 - SpiderMonkey: A minor BitSet::Iterator refactoring. r=nbp
authorDan Gohman <sunfish@google.com>
Mon, 16 Dec 2013 11:13:26 -0800
changeset 160665 b63e9c3e67ac4fefd4e4e95ed323dc60f2aead5a
parent 160664 dbeea0e93b56b586792fe8265779249d22018b2a
child 160666 4361abf1909a0ed422a318c186f684c90255fabb
push id37669
push usersunfish@google.com
push dateMon, 16 Dec 2013 19:13:54 +0000
treeherdermozilla-inbound@cf2cf0c49610 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnbp
bugs950716
milestone29.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 950716 - SpiderMonkey: A minor BitSet::Iterator refactoring. r=nbp
js/src/jit/BitSet.h
--- a/js/src/jit/BitSet.h
+++ b/js/src/jit/BitSet.h
@@ -115,58 +115,62 @@ class BitSet : private TempObject
 class BitSet::Iterator
 {
   private:
     BitSet &set_;
     unsigned index_;
     unsigned word_;
     uint32_t value_;
 
+    void skipEmpty() {
+        // Skip words containing only zeros.
+        while (value_ == 0) {
+            word_++;
+            if (!more())
+                return;
+
+            JS_STATIC_ASSERT(sizeof(value_) * 8 == BitSet::BitsPerWord);
+            index_ = word_ * sizeof(value_) * 8;
+            value_ = set_.bits_[word_];
+        }
+
+        // Be careful: the result of CountTrailingZeroes32 is undefined if the
+        // input is 0.
+        int numZeros = mozilla::CountTrailingZeroes32(value_);
+        index_ += numZeros;
+        value_ >>= numZeros;
+
+        JS_ASSERT_IF(index_ < set_.numBits_, set_.contains(index_));
+    }
+
   public:
     Iterator(BitSet &set) :
       set_(set),
       index_(0),
       word_(0),
       value_(set.bits_[0])
     {
-        if (!set_.contains(index_))
-            (*this)++;
+        skipEmpty();
     }
 
     inline bool more() const {
         return word_ < set_.numWords();
     }
     inline operator bool() const {
         return more();
     }
 
     inline Iterator& operator++(int dummy) {
         JS_ASSERT(more());
         JS_ASSERT(index_ < set_.numBits_);
 
         index_++;
         value_ >>= 1;
 
-        // Skip words containing only zeros.
-        while (value_ == 0) {
-            word_++;
-            if (!more())
-                return *this;
-
-            index_ = word_ * sizeof(value_) * 8;
-            value_ = set_.bits_[word_];
-        }
-
-        // Be careful: the result of CountTrailingZeroes32 is undefined if the
-        // input is 0.
-        int numZeros = mozilla::CountTrailingZeroes32(value_);
-        index_ += numZeros;
-        value_ >>= numZeros;
-
-        JS_ASSERT_IF(index_ < set_.numBits_, set_.contains(index_));
+        skipEmpty();
         return *this;
     }
 
     unsigned int operator *() {
         JS_ASSERT(index_ < set_.numBits_);
         return index_;
     }
 };