Changeset 164097 in webkit
- Timestamp:
- Feb 14, 2014 3:14:56 AM (10 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r164072 r164097 1 2014-02-14 Wojciech Bielawski <w.bielawski@samsung.com> 2 3 (try)append and insert operations don't need new operator for PODs 4 https://bugs.webkit.org/show_bug.cgi?id=128185 5 6 Reviewed by Darin Adler. 7 8 Vector's methods use VectorCopier to copy data. 9 VectorCopier for PODs exteded to be used with different types. For different types placement new copy approach is applied. For the same types memcpy is applied. 10 11 * wtf/Vector.h: 12 (WTF::OverflowHandler>::append): use VectorCopier to copy data. 13 (WTF::OverflowHandler>::tryAppend): use VectorCopier to copy data. 14 (WTF::OverflowHandler>::insert): use VectorCopier to copy data. 15 1 16 2014-02-13 Daniel Bates <dabates@apple.com> 2 17 -
trunk/Source/WTF/wtf/Vector.h
r163850 r164097 137 137 struct VectorCopier<false, T> 138 138 { 139 static void uninitializedCopy(const T* src, const T* srcEnd, T* dst) 139 template<typename U> 140 static void uninitializedCopy(const T* src, const T* srcEnd, U* dst) 140 141 { 141 142 while (src != srcEnd) { 142 new (NotNull, dst) T(*src);143 new (NotNull, dst) U(*src); 143 144 ++dst; 144 145 ++src; … … 150 151 struct VectorCopier<true, T> 151 152 { 152 static void uninitializedCopy(const T* src, const T* srcEnd, T* dst) 153 static void uninitializedCopy(const T* src, const T* srcEnd, T* dst) 153 154 { 154 155 memcpy(dst, src, reinterpret_cast<const char*>(srcEnd) - reinterpret_cast<const char*>(src)); 156 } 157 template<typename U> 158 static void uninitializedCopy(const T* src, const T* srcEnd, U* dst) 159 { 160 VectorCopier<false, T>::uninitializedCopy(src, srcEnd, dst); 155 161 } 156 162 }; … … 1005 1011 // because for instance it allows a PassRefPtr to be appended to a RefPtr vector 1006 1012 // without refcount thrash. 1007 1008 1013 template<typename T, size_t inlineCapacity, typename OverflowHandler> template<typename U> 1009 1014 void Vector<T, inlineCapacity, OverflowHandler>::append(const U* data, size_t dataSize) … … 1017 1022 CRASH(); 1018 1023 T* dest = end(); 1019 for (size_t i = 0; i < dataSize; ++i) 1020 new (NotNull, &dest[i]) T(data[i]); 1024 VectorCopier<std::is_trivial<T>::value, U>::uninitializedCopy(data, &data[dataSize], dest); 1021 1025 m_size = newSize; 1022 1026 } … … 1035 1039 return false; 1036 1040 T* dest = end(); 1037 for (size_t i = 0; i < dataSize; ++i) 1038 new (NotNull, &dest[i]) T(data[i]); 1041 VectorCopier<std::is_trivial<T>::value, U>::uninitializedCopy(data, &data[dataSize], dest); 1039 1042 m_size = newSize; 1040 1043 return true; … … 1098 1101 T* spot = begin() + position; 1099 1102 TypeOperations::moveOverlapping(spot, end(), spot + dataSize); 1100 for (size_t i = 0; i < dataSize; ++i) 1101 new (NotNull, &spot[i]) T(data[i]); 1103 VectorCopier<std::is_trivial<T>::value, U>::uninitializedCopy(data, &data[dataSize], spot); 1102 1104 m_size = newSize; 1103 1105 }
Note: See TracChangeset
for help on using the changeset viewer.