From: Sergey Andreenko Date: Sat, 1 Jul 2017 16:36:36 +0000 (-0700) Subject: Move the bitset iterator for bitsetasuint64inclass inside the bitset. (#12553) X-Git-Tag: accepted/tizen/base/20180629.140029~1083^2~284 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=01088c7b3e47e22c08bfcdc3a73dc5f7a7f1696e;p=platform%2Fupstream%2Fcoreclr.git Move the bitset iterator for bitsetasuint64inclass inside the bitset. (#12553) It is how it is done for others bitsets. --- diff --git a/src/jit/bitsetasshortlong.h b/src/jit/bitsetasshortlong.h index 4f7a972..ef68ba8 100644 --- a/src/jit/bitsetasshortlong.h +++ b/src/jit/bitsetasshortlong.h @@ -537,8 +537,6 @@ public: } }; - friend class Iter; - typedef const BitSetShortLongRep& ValArgType; typedef BitSetShortLongRep RetValType; }; diff --git a/src/jit/bitsetasuint64inclass.h b/src/jit/bitsetasuint64inclass.h index 372f908..3680f2c 100644 --- a/src/jit/bitsetasuint64inclass.h +++ b/src/jit/bitsetasuint64inclass.h @@ -28,7 +28,6 @@ private: /*BitSetTraits*/ BitSetTraits>; friend class BitSetUint64ValueRetType; - friend class BitSetUint64Iter; UINT64 m_bits; @@ -282,58 +281,6 @@ BitSetUint64::BitSetUint64(const BitSetUint64ValueRetType -class BitSetUint64Iter -{ - UINT64 m_bits; - unsigned m_bitNum; - -public: - BitSetUint64Iter(Env env, const BitSetUint64& bs) : m_bits(bs.m_bits), m_bitNum(0) - { - } - - bool NextElem(unsigned* pElem) - { - static const unsigned UINT64_SIZE = 64; - - if ((m_bits & 0x1) != 0) - { - *pElem = m_bitNum; - m_bitNum++; - m_bits >>= 1; - return true; - } - else - { - // Skip groups of 4 zeros -- an optimization for sparse bitsets. - while (m_bitNum < UINT64_SIZE && (m_bits & 0xf) == 0) - { - m_bitNum += 4; - m_bits >>= 4; - } - while (m_bitNum < UINT64_SIZE && (m_bits & 0x1) == 0) - { - m_bitNum += 1; - m_bits >>= 1; - } - if (m_bitNum < UINT64_SIZE) - { - *pElem = m_bitNum; - m_bitNum++; - m_bits >>= 1; - return true; - } - else - { - return false; - } - } - } -}; - template class BitSetOps, /*Brand*/ BSUInt64Class, @@ -512,7 +459,56 @@ public: } #endif - typedef BitSetUint64Iter Iter; + // You *can* clear a bit after it's been iterated. But you shouldn't otherwise mutate the + // bitset during bit iteration. + class Iter + { + UINT64 m_bits; + unsigned m_bitNum; + + public: + Iter(Env env, const BitSetUint64& bs) : m_bits(bs.m_bits), m_bitNum(0) + { + } + + bool NextElem(unsigned* pElem) + { + static const unsigned UINT64_SIZE = 64; + + if ((m_bits & 0x1) != 0) + { + *pElem = m_bitNum; + m_bitNum++; + m_bits >>= 1; + return true; + } + else + { + // Skip groups of 4 zeros -- an optimization for sparse bitsets. + while (m_bitNum < UINT64_SIZE && (m_bits & 0xf) == 0) + { + m_bitNum += 4; + m_bits >>= 4; + } + while (m_bitNum < UINT64_SIZE && (m_bits & 0x1) == 0) + { + m_bitNum += 1; + m_bits >>= 1; + } + if (m_bitNum < UINT64_SIZE) + { + *pElem = m_bitNum; + m_bitNum++; + m_bits >>= 1; + return true; + } + else + { + return false; + } + } + } + }; typedef const BitSetUint64& ValArgType; typedef BitSetUint64ValueRetType RetValType;