Chromium Code Reviews| Index: Source/wtf/Vector.h |
| diff --git a/Source/wtf/Vector.h b/Source/wtf/Vector.h |
| index c2ab2c50a694c2ba1c79e857ef6e75a9fc08c713..24270e709007f2bcbfd361df4ed731993fbf5025 100644 |
| --- a/Source/wtf/Vector.h |
| +++ b/Source/wtf/Vector.h |
| @@ -162,10 +162,11 @@ 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 T* src, const T* srcEnd, U* dst) |
|
Mikhail
2014/02/25 14:11:32
I'd change it to
template<typename U>
static void
w.bielawski
2014/02/26 16:40:44
Done.
|
| { |
| while (src != srcEnd) { |
| - new (NotNull, dst) T(*src); |
| + new (NotNull, dst) U(*src); |
| ++dst; |
| ++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 T* src, const T* srcEnd, U* dst) |
| + { |
| + VectorCopier<false, T>::uninitializedCopy(src, srcEnd, dst); |
| + } |
| }; |
| template <bool canFillWithMemset, typename T> |
| @@ -963,8 +969,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, U>::uninitializedCopy(data, &data[dataSize], dest); |
| m_size = newSize; |
| } |
| @@ -1023,8 +1028,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, U>::uninitializedCopy(data, &data[dataSize], spot); |
| m_size = newSize; |
| } |