diff options
Diffstat (limited to 'sfx2/source/bastyp')
-rw-r--r-- | sfx2/source/bastyp/bitset.cxx | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/sfx2/source/bastyp/bitset.cxx b/sfx2/source/bastyp/bitset.cxx index 621e56599ce6..bff716d0a487 100644 --- a/sfx2/source/bastyp/bitset.cxx +++ b/sfx2/source/bastyp/bitset.cxx @@ -283,24 +283,19 @@ bool BitSet::operator==( const BitSet& rSet ) const return true; } - - // counts the number of 1-bits in the parameter - -sal_uInt16 BitSet::CountBits( sal_uInt32 nBits ) +// Wegner/Kernighan/Ritchie method +sal_uInt16 BitSet::CountBits(sal_uInt32 nBits) { - sal_uInt16 nCount = 0; - int nBit = 32; - while ( nBit-- && nBits ) - { if ( ( (long)nBits ) < 0 ) - ++nCount; - nBits = nBits << 1; + sal_uInt32 nCount = 0; + while (nBits) + { + nBits &= nBits - 1; // clear the least significant bit set + ++nCount; } return nCount; } - - sal_uInt16 IndexBitSet::GetFreeIndex() { for(sal_uInt16 i=0;i<USHRT_MAX;i++) |