Vector::insert and Vector::append may use memcpy for POD types.

It will improve performance when POD types are copied, by providing
a missing implementation of VectorCopier and using it in
two places which were previously always taking the "new" allocation
path even though they could have used VectorCopier and used
memcpy for POD types.

NOTRY=true

Review URL: https://codereview.chromium.org/178313002

git-svn-id: svn://svn.chromium.org/blink/trunk@168472 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 6e660ae5
......@@ -162,7 +162,8 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE;
template<typename T>
struct VectorCopier<false, T>
{
static void uninitializedCopy(const T* src, const T* srcEnd, T* dst)
template<typename U>
static void uninitializedCopy(const U* src, const U* srcEnd, T* dst)
{
while (src != srcEnd) {
new (NotNull, dst) T(*src);
......@@ -179,6 +180,11 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE;
{
memcpy(dst, src, reinterpret_cast<const char*>(srcEnd) - reinterpret_cast<const char*>(src));
}
template<typename U>
static void uninitializedCopy(const U* src, const U* srcEnd, T* dst)
{
VectorCopier<false, T>::uninitializedCopy(src, srcEnd, dst);
}
};
template <bool canFillWithMemset, typename T>
......@@ -962,8 +968,7 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE;
}
RELEASE_ASSERT(newSize >= m_size);
T* dest = end();
for (size_t i = 0; i < dataSize; ++i)
new (NotNull, &dest[i]) T(data[i]);
VectorCopier<VectorTraits<T>::canCopyWithMemcpy, T>::uninitializedCopy(data, &data[dataSize], dest);
m_size = newSize;
}
......@@ -1022,8 +1027,7 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE;
RELEASE_ASSERT(newSize >= m_size);
T* spot = begin() + position;
TypeOperations::moveOverlapping(spot, end(), spot + dataSize);
for (size_t i = 0; i < dataSize; ++i)
new (NotNull, &spot[i]) T(data[i]);
VectorCopier<VectorTraits<T>::canCopyWithMemcpy, T>::uninitializedCopy(data, &data[dataSize], spot);
m_size = newSize;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment