OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkTArray_DEFINED | 8 #ifndef SkTArray_DEFINED |
9 #define SkTArray_DEFINED | 9 #define SkTArray_DEFINED |
10 | 10 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 if (newCount > fCount) { | 266 if (newCount > fCount) { |
267 this->push_back_n(newCount - fCount); | 267 this->push_back_n(newCount - fCount); |
268 } else if (newCount < fCount) { | 268 } else if (newCount < fCount) { |
269 this->pop_back_n(fCount - newCount); | 269 this->pop_back_n(fCount - newCount); |
270 } | 270 } |
271 } | 271 } |
272 | 272 |
273 /** Swaps the contents of this array with that array. Does a pointer swap if
possible, | 273 /** Swaps the contents of this array with that array. Does a pointer swap if
possible, |
274 otherwise copies the T values. */ | 274 otherwise copies the T values. */ |
275 void swap(SkTArray* that) { | 275 void swap(SkTArray* that) { |
| 276 if (this == that) { |
| 277 return; |
| 278 } |
276 if (this->fPreAllocMemArray != this->fItemArray && | 279 if (this->fPreAllocMemArray != this->fItemArray && |
277 that->fPreAllocMemArray != that->fItemArray) { | 280 that->fPreAllocMemArray != that->fItemArray) { |
278 // If neither is using a preallocated array then just swap. | 281 // If neither is using a preallocated array then just swap. |
279 SkTSwap(fItemArray, that->fItemArray); | 282 SkTSwap(fItemArray, that->fItemArray); |
280 SkTSwap(fCount, that->fCount); | 283 SkTSwap(fCount, that->fCount); |
281 SkTSwap(fAllocCount, that->fAllocCount); | 284 SkTSwap(fAllocCount, that->fAllocCount); |
282 } else { | 285 } else { |
283 // This could be more optimal... | 286 // This could be more optimal... |
284 SkTArray copy(*that); | 287 SkTArray copy(*that); |
285 *that = *this; | 288 *that = *this; |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 SkSTArray& operator= (const INHERITED& array) { | 540 SkSTArray& operator= (const INHERITED& array) { |
538 INHERITED::operator=(array); | 541 INHERITED::operator=(array); |
539 return *this; | 542 return *this; |
540 } | 543 } |
541 | 544 |
542 private: | 545 private: |
543 SkAlignedSTStorage<N,T> fStorage; | 546 SkAlignedSTStorage<N,T> fStorage; |
544 }; | 547 }; |
545 | 548 |
546 #endif | 549 #endif |
OLD | NEW |