X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/9bcd318d5fa2a38139c9651d263a06c797529333..ba379fdc102753d6be2c4d937058fe40257329fe:/wtf/Vector.h diff --git a/wtf/Vector.h b/wtf/Vector.h index 95ff5b3..f8a5be2 100644 --- a/wtf/Vector.h +++ b/wtf/Vector.h @@ -21,16 +21,17 @@ #ifndef WTF_Vector_h #define WTF_Vector_h -#include "Assertions.h" -#include "FastMalloc.h" +#include "FastAllocBase.h" #include "Noncopyable.h" #include "NotFound.h" #include "VectorTraits.h" #include -#include -#include #include +#if PLATFORM(QT) +#include +#endif + namespace WTF { using std::min; @@ -377,7 +378,8 @@ namespace WTF { VectorBuffer(size_t capacity) : Base(inlineBuffer(), inlineCapacity) { - allocateBuffer(capacity); + if (capacity > inlineCapacity) + Base::allocateBuffer(capacity); } ~VectorBuffer() @@ -389,6 +391,10 @@ namespace WTF { { if (newCapacity > inlineCapacity) Base::allocateBuffer(newCapacity); + else { + m_buffer = inlineBuffer(); + m_capacity = inlineCapacity; + } } void deallocateBuffer(T* bufferToDeallocate) @@ -433,7 +439,7 @@ namespace WTF { }; template - class Vector { + class Vector : public FastAllocBase { private: typedef VectorBuffer Buffer; typedef VectorTypeOperations TypeOperations; @@ -566,6 +572,32 @@ namespace WTF { Buffer m_buffer; }; +#if PLATFORM(QT) + template + QDataStream& operator<<(QDataStream& stream, const Vector& data) + { + stream << qint64(data.size()); + foreach (const T& i, data) + stream << i; + return stream; + } + + template + QDataStream& operator>>(QDataStream& stream, Vector& data) + { + data.clear(); + qint64 count; + T item; + stream >> count; + data.reserveCapacity(count); + for (qint64 i = 0; i < count; ++i) { + stream >> item; + data.append(item); + } + return stream; + } +#endif + template Vector::Vector(const Vector& other) : m_size(other.size()) @@ -692,7 +724,7 @@ namespace WTF { } template - void Vector::resize(size_t size) + inline void Vector::resize(size_t size) { if (size <= m_size) TypeOperations::destruct(begin() + size, end()); @@ -790,7 +822,7 @@ namespace WTF { } template template - inline void Vector::append(const U& val) + ALWAYS_INLINE void Vector::append(const U& val) { const U* ptr = &val; if (size() == capacity()) {