Changeset 561 for trunk/src/corelib/tools/qvarlengtharray.h
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/corelib/tools/qvarlengtharray.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the QtCore module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 52 52 53 53 QT_MODULE(Core) 54 55 56 54 57 55 58 // Prealloc = 256 by default, specified in qcontainerfwd.h … … 123 126 124 127 private: 128 125 129 void realloc(int size, int alloc); 126 130 … … 141 145 if (s > Prealloc) { 142 146 ptr = reinterpret_cast<T *>(qMalloc(s * sizeof(T))); 147 143 148 a = s; 144 149 } else { … … 162 167 163 168 template <class T, int Prealloc> 164 Q_OUTOFLINE_TEMPLATE void QVarLengthArray<T, Prealloc>::append(const T *abuf, int asize)169 Q_OUTOFLINE_TEMPLATE void QVarLengthArray<T, Prealloc>::append(const T *abuf, int ) 165 170 { 166 171 Q_ASSERT(abuf); 167 if ( asize<= 0)172 if ( <= 0) 168 173 return; 169 174 170 const int idx = s; 171 const int news = s + asize; 172 if (news >= a) 173 realloc(s, qMax(s<<1, news)); 174 s = news; 175 176 if (QTypeInfo<T>::isComplex) { 177 T *i = ptr + idx; 178 T *j = i + asize; 179 while (i < j) 180 new (i++) T(*abuf++); 175 const int asize = s + increment; 176 177 if (asize >= a) 178 realloc(s, qMax(s*2, asize)); 179 180 if (QTypeInfo<T>::isComplex) { 181 // call constructor for new objects (which can throw) 182 while (s < asize) 183 new (ptr+(s++)) T(*abuf++); 181 184 } else { 182 qMemCopy(&ptr[idx], abuf, asize * sizeof(T)); 185 qMemCopy(&ptr[s], abuf, increment * sizeof(T)); 186 s = asize; 183 187 } 184 188 } … … 190 194 T *oldPtr = ptr; 191 195 int osize = s; 192 s = asize;196 s = asize; 193 197 194 198 if (aalloc != a) { 195 199 ptr = reinterpret_cast<T *>(qMalloc(aalloc * sizeof(T))); 200 196 201 if (ptr) { 202 197 203 a = aalloc; 198 204 199 205 if (QTypeInfo<T>::isStatic) { 200 T *i = ptr + osize; 201 T *j = oldPtr + osize; 202 while (i != ptr) { 203 new (--i) T(*--j); 204 j->~T(); 206 QT_TRY { 207 // copy all the old elements 208 const int copySize = qMin(asize, osize); 209 while (s < copySize) { 210 new (ptr+s) T(*(oldPtr+s)); 211 (oldPtr+s)->~T(); 212 s++; 213 } 214 } QT_CATCH(...) { 215 // clean up all the old objects and then free the old ptr 216 int sClean = s; 217 while (sClean < osize) 218 (oldPtr+(sClean++))->~T(); 219 if (oldPtr != reinterpret_cast<T *>(array) && oldPtr != ptr) 220 qFree(oldPtr); 221 QT_RETHROW; 205 222 } 206 223 } else { 207 qMemCopy(ptr, oldPtr, osize * sizeof(T)); 224 qMemCopy(ptr, oldPtr, qMin(asize, osize) * sizeof(T)); 225 s = asize; 208 226 } 209 227 } else { 210 228 ptr = oldPtr; 211 s = 0; 212 asize = 0; 213 } 214 } 215 216 if (QTypeInfo<T>::isComplex) { 217 if (asize < osize) { 218 T *i = oldPtr + osize; 219 T *j = oldPtr + asize; 220 while (i-- != j) 221 i->~T(); 222 } else { 223 T *i = ptr + asize; 224 T *j = ptr + osize; 225 while (i != j) 226 new (--i) T; 227 } 229 return; 230 } 231 } 232 233 if (QTypeInfo<T>::isComplex) { 234 while (osize > asize) 235 (oldPtr+(--osize))->~T(); 236 if( oldPtr == ptr ) 237 s = osize; 228 238 } 229 239 230 240 if (oldPtr != reinterpret_cast<T *>(array) && oldPtr != ptr) 231 241 qFree(oldPtr); 242 243 244 245 246 247 248 249 232 250 } 233 251
Note:
See TracChangeset
for help on using the changeset viewer.