summaryrefslogtreecommitdiff
path: root/sfx2/source/bastyp
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2014-11-12 11:26:37 +0000
committerCaolán McNamara <caolanm@redhat.com>2014-11-12 12:25:20 +0000
commit3cd91d1204f8982b2ac7861e4479c8614a8d960f (patch)
tree7041f48083922e903e376c4baddc912b08881565 /sfx2/source/bastyp
parentc24df3e0904cdf8aa289db435ad3e6dc8c25a437 (diff)
coverity#735490 reimplement bit counting
with a classic solution rather than a bizarro one that confuses coverity Change-Id: Id9427a47693897683193c0c778f0cd6c39740f6f
Diffstat (limited to 'sfx2/source/bastyp')
-rw-r--r--sfx2/source/bastyp/bitset.cxx19
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++)