Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1924)

Unified Diff: Source/wtf/Vector.h

Issue 178313002: Vector::insert and Vector::append may use memcpy for POD types (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Corrections after review Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/Vector.h
diff --git a/Source/wtf/Vector.h b/Source/wtf/Vector.h
index c2ab2c50a694c2ba1c79e857ef6e75a9fc08c713..260bd580f2039e31f0dfdaab1263028f45b372a1 100644
--- a/Source/wtf/Vector.h
+++ b/Source/wtf/Vector.h
@@ -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>
@@ -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, T>::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, T>::uninitializedCopy(data, &data[dataSize], spot);
m_size = newSize;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698