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

Side by Side Diff: include/core/SkTDArray.h

Issue 563633003: Assert SkTDArray::pop() doesn't underflow. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkTDArray_DEFINED 10 #ifndef SkTDArray_DEFINED
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 int count = SkMin32(max, fCount - index); 275 int count = SkMin32(max, fCount - index);
276 memcpy(dst, fArray + index, sizeof(T) * count); 276 memcpy(dst, fArray + index, sizeof(T) * count);
277 return count; 277 return count;
278 } 278 }
279 279
280 void copy(T* dst) const { 280 void copy(T* dst) const {
281 this->copyRange(dst, 0, fCount); 281 this->copyRange(dst, 0, fCount);
282 } 282 }
283 283
284 // routines to treat the array like a stack 284 // routines to treat the array like a stack
285 T* push() { return this->append(); } 285 T* push() { return this->append(); }
286 void push(const T& elem) { *this->append() = elem; } 286 void push(const T& elem) { *this->append() = elem; }
287 const T& top() const { return (*this)[fCount - 1]; } 287 const T& top() const { return (*this)[fCount - 1]; }
288 T& top() { return (*this)[fCount - 1]; } 288 T& top() { return (*this)[fCount - 1]; }
289 void pop(T* elem) { if (elem) *elem = (*this)[fCount - 1]; --fCount; } 289 void pop(T* elem) { SkASSERT(fCount > 0); if (elem) *elem = (*this)[fCou nt - 1]; --fCount; }
290 void pop() { --fCount; } 290 void pop() { SkASSERT(fCount > 0); --fCount; }
291 291
292 void deleteAll() { 292 void deleteAll() {
293 T* iter = fArray; 293 T* iter = fArray;
294 T* stop = fArray + fCount; 294 T* stop = fArray + fCount;
295 while (iter < stop) { 295 while (iter < stop) {
296 SkDELETE (*iter); 296 SkDELETE (*iter);
297 iter += 1; 297 iter += 1;
298 } 298 }
299 this->reset(); 299 this->reset();
300 } 300 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 fReserve = count + 4; 380 fReserve = count + 4;
381 fReserve += fReserve / 4; 381 fReserve += fReserve / 4;
382 fArray = (T*)sk_realloc_throw(fArray, fReserve * sizeof(T)); 382 fArray = (T*)sk_realloc_throw(fArray, fReserve * sizeof(T));
383 #ifdef SK_DEBUG 383 #ifdef SK_DEBUG
384 fData = (ArrayT*)fArray; 384 fData = (ArrayT*)fArray;
385 #endif 385 #endif
386 } 386 }
387 }; 387 };
388 388
389 #endif 389 #endif
OLDNEW
« 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