Modified: branches/safari-537-branch/Source/WTF/wtf/SizeLimits.cpp (153616 => 153617)
--- branches/safari-537-branch/Source/WTF/wtf/SizeLimits.cpp 2013-08-01 22:27:10 UTC (rev 153616)
+++ branches/safari-537-branch/Source/WTF/wtf/SizeLimits.cpp 2013-08-01 22:34:52 UTC (rev 153617)
@@ -54,13 +54,20 @@
// Don't add anything here because this should stay small.
};
#endif
+template<typename T, unsigned inlineCapacity>
+struct SameSizeAsVectorWithInlineCapacity {
+ void* bufferPointer;
+ unsigned capacity;
+ unsigned size;
+ AlignedBuffer<inlineCapacity * sizeof(T), WTF_ALIGN_OF(T)> inlineBuffer;
+};
COMPILE_ASSERT(sizeof(OwnPtr<int>) == sizeof(int*), OwnPtr_should_stay_small);
COMPILE_ASSERT(sizeof(PassRefPtr<RefCounted<int> >) == sizeof(int*), PassRefPtr_should_stay_small);
COMPILE_ASSERT(sizeof(RefCounted<int>) == sizeof(SameSizeAsRefCounted), RefCounted_should_stay_small);
COMPILE_ASSERT(sizeof(RefCountedCustomAllocated<int>) == sizeof(SameSizeAsRefCounted), RefCountedCustomAllocated_should_stay_small);
COMPILE_ASSERT(sizeof(RefPtr<RefCounted<int> >) == sizeof(int*), RefPtr_should_stay_small);
-COMPILE_ASSERT(sizeof(Vector<int>) == sizeof(int*) + 2 * sizeof(int), Vector_should_stay_small);
-COMPILE_ASSERT(sizeof(Vector<int, 1>) == 2 * sizeof(int*) + 2 * sizeof(int), Vector_should_stay_small);
-
+COMPILE_ASSERT(sizeof(Vector<int, 1>) == sizeof(SameSizeAsVectorWithInlineCapacity<int, 1>), Vector_should_stay_small);
+COMPILE_ASSERT(sizeof(Vector<int, 2>) == sizeof(SameSizeAsVectorWithInlineCapacity<int, 2>), Vector_should_stay_small);
+COMPILE_ASSERT(sizeof(Vector<int, 3>) == sizeof(SameSizeAsVectorWithInlineCapacity<int, 3>), Vector_should_stay_small);
}
Modified: branches/safari-537-branch/Source/WTF/wtf/Vector.h (153616 => 153617)
--- branches/safari-537-branch/Source/WTF/wtf/Vector.h 2013-08-01 22:27:10 UTC (rev 153616)
+++ branches/safari-537-branch/Source/WTF/wtf/Vector.h 2013-08-01 22:34:52 UTC (rev 153617)
@@ -319,12 +319,14 @@
VectorBufferBase()
: m_buffer(0)
, m_capacity(0)
+ , m_size(0)
{
}
- VectorBufferBase(T* buffer, size_t capacity)
+ VectorBufferBase(T* buffer, size_t capacity, size_t size)
: m_buffer(buffer)
, m_capacity(capacity)
+ , m_size(size)
{
}
@@ -335,6 +337,7 @@
T* m_buffer;
unsigned m_capacity;
+ unsigned m_size; // Only used by the Vector subclass, but placed here to avoid padding the struct.
};
template<typename T, size_t inlineCapacity>
@@ -349,8 +352,9 @@
{
}
- VectorBuffer(size_t capacity)
+ VectorBuffer(size_t capacity, size_t size = 0)
{
+ m_size = size;
// Calling malloc(0) might take a lock and may actually do an
// allocation on some systems.
if (capacity)
@@ -380,6 +384,10 @@
using Base::capacity;
using Base::releaseBuffer;
+
+ protected:
+ using Base::m_size;
+
private:
using Base::m_buffer;
using Base::m_capacity;
@@ -392,12 +400,12 @@
typedef VectorBufferBase<T> Base;
public:
VectorBuffer()
- : Base(inlineBuffer(), inlineCapacity)
+ : Base(inlineBuffer(), inlineCapacity, 0)
{
}
- VectorBuffer(size_t capacity)
- : Base(inlineBuffer(), inlineCapacity)
+ VectorBuffer(size_t capacity, size_t size = 0)
+ : Base(inlineBuffer(), inlineCapacity, size)
{
if (capacity > inlineCapacity)
Base::allocateBuffer(capacity);
@@ -486,6 +494,9 @@
return Base::releaseBuffer();
}
+ protected:
+ using Base::m_size;
+
private:
using Base::m_buffer;
using Base::m_capacity;
@@ -520,13 +531,11 @@
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Vector()
- : m_size(0)
{
}
explicit Vector(size_t size)
- : Base(size)
- , m_size(size)
+ : Base(size, size)
{
if (begin())
TypeOperations::initialize(begin(), end());
@@ -638,8 +647,7 @@
}
Vector(size_t size, const T& val)
- : Base(size)
- , m_size(size)
+ : Base(size, size)
{
if (begin())
TypeOperations::uninitializedFill(begin(), end(), val);
@@ -670,8 +678,7 @@
template<typename U> U* expandCapacity(size_t newMinCapacity, U*);
template<typename U> void appendSlowCase(const U&);
- unsigned m_size;
-
+ using Base::m_size;
using Base::buffer;
using Base::capacity;
using Base::swap;
@@ -686,8 +693,7 @@
template<typename T, size_t inlineCapacity, typename OverflowHandler>
Vector<T, inlineCapacity, OverflowHandler>::Vector(const Vector& other)
- : Base(other.capacity())
- , m_size(other.size())
+ : Base(other.capacity(), other.size())
{
if (begin())
TypeOperations::uninitializedCopy(other.begin(), other.end(), begin());
@@ -696,8 +702,7 @@
template<typename T, size_t inlineCapacity, typename OverflowHandler>
template<size_t otherCapacity, typename otherOverflowBehaviour>
Vector<T, inlineCapacity, OverflowHandler>::Vector(const Vector<T, otherCapacity, otherOverflowBehaviour>& other)
- : Base(other.capacity())
- , m_size(other.size())
+ : Base(other.capacity(), other.size())
{
if (begin())
TypeOperations::uninitializedCopy(other.begin(), other.end(), begin());
@@ -767,7 +772,6 @@
#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
template<typename T, size_t inlineCapacity, typename OverflowHandler>
Vector<T, inlineCapacity, OverflowHandler>::Vector(Vector<T, inlineCapacity, OverflowHandler>&& other)
- : m_size(0)
{
// It's a little weird to implement a move constructor using swap but this way we
// don't have to add a move constructor to VectorBuffer.