OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 Base::deallocateBuffer(oldBuffer); | 1005 Base::deallocateBuffer(oldBuffer); |
1006 } | 1006 } |
1007 | 1007 |
1008 // Templatizing these is better than just letting the conversion happen impl
icitly, | 1008 // Templatizing these is better than just letting the conversion happen impl
icitly, |
1009 // because for instance it allows a PassRefPtr to be appended to a RefPtr ve
ctor | 1009 // because for instance it allows a PassRefPtr to be appended to a RefPtr ve
ctor |
1010 // without refcount thrash. | 1010 // without refcount thrash. |
1011 | 1011 |
1012 template<typename T, size_t inlineCapacity, typename Allocator> template<typ
ename U> | 1012 template<typename T, size_t inlineCapacity, typename Allocator> template<typ
ename U> |
1013 void Vector<T, inlineCapacity, Allocator>::append(const U* data, size_t data
Size) | 1013 void Vector<T, inlineCapacity, Allocator>::append(const U* data, size_t data
Size) |
1014 { | 1014 { |
| 1015 ASSERT(Allocator::isAllocationAllowed()); |
1015 size_t newSize = m_size + dataSize; | 1016 size_t newSize = m_size + dataSize; |
1016 if (newSize > capacity()) { | 1017 if (newSize > capacity()) { |
1017 data = expandCapacity(newSize, data); | 1018 data = expandCapacity(newSize, data); |
1018 ASSERT(begin()); | 1019 ASSERT(begin()); |
1019 } | 1020 } |
1020 RELEASE_ASSERT(newSize >= m_size); | 1021 RELEASE_ASSERT(newSize >= m_size); |
1021 T* dest = end(); | 1022 T* dest = end(); |
1022 VectorCopier<VectorTraits<T>::canCopyWithMemcpy, T>::uninitializedCopy(d
ata, &data[dataSize], dest); | 1023 VectorCopier<VectorTraits<T>::canCopyWithMemcpy, T>::uninitializedCopy(d
ata, &data[dataSize], dest); |
1023 m_size = newSize; | 1024 m_size = newSize; |
1024 } | 1025 } |
1025 | 1026 |
1026 template<typename T, size_t inlineCapacity, typename Allocator> template<typ
ename U> | 1027 template<typename T, size_t inlineCapacity, typename Allocator> template<typ
ename U> |
1027 ALWAYS_INLINE void Vector<T, inlineCapacity, Allocator>::append(const U& val
) | 1028 ALWAYS_INLINE void Vector<T, inlineCapacity, Allocator>::append(const U& val
) |
1028 { | 1029 { |
| 1030 ASSERT(Allocator::isAllocationAllowed()); |
1029 if (LIKELY(size() != capacity())) { | 1031 if (LIKELY(size() != capacity())) { |
1030 new (NotNull, end()) T(val); | 1032 new (NotNull, end()) T(val); |
1031 ++m_size; | 1033 ++m_size; |
1032 return; | 1034 return; |
1033 } | 1035 } |
1034 | 1036 |
1035 appendSlowCase(val); | 1037 appendSlowCase(val); |
1036 } | 1038 } |
1037 | 1039 |
1038 template<typename T, size_t inlineCapacity, typename Allocator> template<typ
ename U> | 1040 template<typename T, size_t inlineCapacity, typename Allocator> template<typ
ename U> |
(...skipping 23 matching lines...) Expand all Loading... |
1062 | 1064 |
1063 template<typename T, size_t inlineCapacity, typename Allocator> template<typ
ename U, size_t otherCapacity, typename OtherAllocator> | 1065 template<typename T, size_t inlineCapacity, typename Allocator> template<typ
ename U, size_t otherCapacity, typename OtherAllocator> |
1064 inline void Vector<T, inlineCapacity, Allocator>::appendVector(const Vector<
U, otherCapacity, OtherAllocator>& val) | 1066 inline void Vector<T, inlineCapacity, Allocator>::appendVector(const Vector<
U, otherCapacity, OtherAllocator>& val) |
1065 { | 1067 { |
1066 append(val.begin(), val.size()); | 1068 append(val.begin(), val.size()); |
1067 } | 1069 } |
1068 | 1070 |
1069 template<typename T, size_t inlineCapacity, typename Allocator> template<typ
ename U> | 1071 template<typename T, size_t inlineCapacity, typename Allocator> template<typ
ename U> |
1070 void Vector<T, inlineCapacity, Allocator>::insert(size_t position, const U*
data, size_t dataSize) | 1072 void Vector<T, inlineCapacity, Allocator>::insert(size_t position, const U*
data, size_t dataSize) |
1071 { | 1073 { |
| 1074 ASSERT(Allocator::isAllocationAllowed()); |
1072 RELEASE_ASSERT(position <= size()); | 1075 RELEASE_ASSERT(position <= size()); |
1073 size_t newSize = m_size + dataSize; | 1076 size_t newSize = m_size + dataSize; |
1074 if (newSize > capacity()) { | 1077 if (newSize > capacity()) { |
1075 data = expandCapacity(newSize, data); | 1078 data = expandCapacity(newSize, data); |
1076 ASSERT(begin()); | 1079 ASSERT(begin()); |
1077 } | 1080 } |
1078 RELEASE_ASSERT(newSize >= m_size); | 1081 RELEASE_ASSERT(newSize >= m_size); |
1079 T* spot = begin() + position; | 1082 T* spot = begin() + position; |
1080 TypeOperations::moveOverlapping(spot, end(), spot + dataSize); | 1083 TypeOperations::moveOverlapping(spot, end(), spot + dataSize); |
1081 VectorCopier<VectorTraits<T>::canCopyWithMemcpy, T>::uninitializedCopy(d
ata, &data[dataSize], spot); | 1084 VectorCopier<VectorTraits<T>::canCopyWithMemcpy, T>::uninitializedCopy(d
ata, &data[dataSize], spot); |
1082 m_size = newSize; | 1085 m_size = newSize; |
1083 } | 1086 } |
1084 | 1087 |
1085 template<typename T, size_t inlineCapacity, typename Allocator> template<typ
ename U> | 1088 template<typename T, size_t inlineCapacity, typename Allocator> template<typ
ename U> |
1086 inline void Vector<T, inlineCapacity, Allocator>::insert(size_t position, co
nst U& val) | 1089 inline void Vector<T, inlineCapacity, Allocator>::insert(size_t position, co
nst U& val) |
1087 { | 1090 { |
| 1091 ASSERT(Allocator::isAllocationAllowed()); |
1088 RELEASE_ASSERT(position <= size()); | 1092 RELEASE_ASSERT(position <= size()); |
1089 const U* data = &val; | 1093 const U* data = &val; |
1090 if (size() == capacity()) { | 1094 if (size() == capacity()) { |
1091 data = expandCapacity(size() + 1, data); | 1095 data = expandCapacity(size() + 1, data); |
1092 ASSERT(begin()); | 1096 ASSERT(begin()); |
1093 } | 1097 } |
1094 T* spot = begin() + position; | 1098 T* spot = begin() + position; |
1095 TypeOperations::moveOverlapping(spot, end(), spot + 1); | 1099 TypeOperations::moveOverlapping(spot, end(), spot + 1); |
1096 new (NotNull, spot) T(*data); | 1100 new (NotNull, spot) T(*data); |
1097 ++m_size; | 1101 ++m_size; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 struct NeedsTracing<Vector<T, N> > { | 1207 struct NeedsTracing<Vector<T, N> > { |
1204 static const bool value = false; | 1208 static const bool value = false; |
1205 }; | 1209 }; |
1206 #endif | 1210 #endif |
1207 | 1211 |
1208 } // namespace WTF | 1212 } // namespace WTF |
1209 | 1213 |
1210 using WTF::Vector; | 1214 using WTF::Vector; |
1211 | 1215 |
1212 #endif // WTF_Vector_h | 1216 #endif // WTF_Vector_h |
OLD | NEW |