From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WTF/wtf/BitVector.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'Source/WTF/wtf/BitVector.cpp') 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 @@ -182,6 +182,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--;) { -- cgit v1.2.1