diff options
author | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2012-05-14 15:01:19 +0000 |
---|---|---|
committer | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2012-05-14 15:01:19 +0000 |
commit | 03a3811ab48139f45cf47f1168788e630af0d40b (patch) | |
tree | e511159871ccdfc06291e52021d0f913ac171c87 /include/llvm/ADT/BitVector.h | |
parent | 734dde8e051d34ac34cc58eb31cf2e6fa3ac3f37 (diff) |
Add BitVector::anyCommon().
The existing operation (A & B).any() is very slow.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156760 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/BitVector.h')
-rw-r--r-- | include/llvm/ADT/BitVector.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/include/llvm/ADT/BitVector.h b/include/llvm/ADT/BitVector.h index 7e0b5ba371..bf6d76fbcc 100644 --- a/include/llvm/ADT/BitVector.h +++ b/include/llvm/ADT/BitVector.h @@ -272,6 +272,16 @@ public: return (*this)[Idx]; } + /// Test if any common bits are set. + bool anyCommon(const BitVector &RHS) const { + unsigned ThisWords = NumBitWords(size()); + unsigned RHSWords = NumBitWords(RHS.size()); + for (unsigned i = 0, e = std::min(ThisWords, RHSWords); i != e; ++i) + if (Bits[i] & RHS.Bits[i]) + return true; + return false; + } + // Comparison operators. bool operator==(const BitVector &RHS) const { unsigned ThisWords = NumBitWords(size()); |