diff options
Diffstat (limited to 'Source/WTF/wtf/FastBitVector.cpp')
-rw-r--r-- | Source/WTF/wtf/FastBitVector.cpp | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/Source/WTF/wtf/FastBitVector.cpp b/Source/WTF/wtf/FastBitVector.cpp index 3abccea73..eed316975 100644 --- a/Source/WTF/wtf/FastBitVector.cpp +++ b/Source/WTF/wtf/FastBitVector.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Apple Inc. All rights reserved. + * Copyright (C) 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,14 +26,50 @@ #include "config.h" #include "FastBitVector.h" -#include "PrintStream.h" - namespace WTF { -void FastBitVector::dump(PrintStream& out) const +void FastBitVectorWordOwner::setEqualsSlow(const FastBitVectorWordOwner& other) +{ + uint32_t* newArray = static_cast<uint32_t*>( + fastCalloc(other.arrayLength(), sizeof(uint32_t))); + memcpy(newArray, other.m_words, other.arrayLength() * sizeof(uint32_t)); + if (m_words) + fastFree(m_words); + m_words = newArray; + m_numBits = other.m_numBits; +} + +void FastBitVectorWordOwner::resizeSlow(size_t numBits) +{ + size_t newLength = fastBitVectorArrayLength(numBits); + + // Use fastCalloc instead of fastRealloc because we expect the common + // use case for this method to be initializing the size of the bitvector. + + uint32_t* newArray = static_cast<uint32_t*>(fastCalloc(newLength, sizeof(uint32_t))); + memcpy(newArray, m_words, arrayLength() * sizeof(uint32_t)); + if (m_words) + fastFree(m_words); + m_words = newArray; +} + +void FastBitVector::clearRange(size_t begin, size_t end) { - for (unsigned i = 0; i < m_numBits; ++i) - out.print(get(i) ? "1" : "-"); + if (end - begin < 32) { + for (size_t i = begin; i < end; ++i) + at(i) = false; + return; + } + + size_t endBeginSlop = (begin + 31) & ~31; + size_t beginEndSlop = end & ~31; + + for (size_t i = begin; i < endBeginSlop; ++i) + at(i) = false; + for (size_t i = beginEndSlop; i < end; ++i) + at(i) = false; + for (size_t i = endBeginSlop / 32; i < beginEndSlop / 32; ++i) + m_words.word(i) = 0; } } // namespace WTF |