summaryrefslogtreecommitdiff
path: root/Source/WTF/wtf/BitVector.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WTF/wtf/BitVector.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WTF/wtf/BitVector.cpp')
-rw-r--r--Source/WTF/wtf/BitVector.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/Source/WTF/wtf/BitVector.cpp b/Source/WTF/wtf/BitVector.cpp
index f60856c39..736ff7d28 100644
--- a/Source/WTF/wtf/BitVector.cpp
+++ b/Source/WTF/wtf/BitVector.cpp
@@ -183,6 +183,50 @@ size_t BitVector::bitCountSlow() const
bool BitVector::equalsSlowCase(const BitVector& other) const
{
+ bool result = equalsSlowCaseFast(other);
+ ASSERT(result == equalsSlowCaseSimple(other));
+ return result;
+}
+
+bool BitVector::equalsSlowCaseFast(const BitVector& other) const
+{
+ if (isInline() != other.isInline())
+ return equalsSlowCaseSimple(other);
+
+ const OutOfLineBits* myBits = outOfLineBits();
+ const OutOfLineBits* otherBits = other.outOfLineBits();
+
+ size_t myNumWords = myBits->numWords();
+ size_t otherNumWords = otherBits->numWords();
+ size_t minNumWords;
+ size_t maxNumWords;
+
+ const OutOfLineBits* longerBits;
+ if (myNumWords < otherNumWords) {
+ minNumWords = myNumWords;
+ maxNumWords = otherNumWords;
+ longerBits = otherBits;
+ } else {
+ minNumWords = otherNumWords;
+ maxNumWords = myNumWords;
+ longerBits = myBits;
+ }
+
+ for (size_t i = minNumWords; i < maxNumWords; ++i) {
+ if (longerBits->bits()[i])
+ return false;
+ }
+
+ for (size_t i = minNumWords; i--;) {
+ if (myBits->bits()[i] != otherBits->bits()[i])
+ return false;
+ }
+
+ return true;
+}
+
+bool BitVector::equalsSlowCaseSimple(const BitVector& other) const
+{
// This is really cheesy, but probably good enough for now.
for (unsigned i = std::max(size(), other.size()); i--;) {
if (get(i) != other.get(i))