diff options
author | bsalomon <bsalomon@google.com> | 2014-09-05 06:13:43 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-05 06:13:43 -0700 |
commit | a1ae66d252edf6da932caed1fe43d11216e56c0e (patch) | |
tree | 8247f3d0f63830970f71bd1bc5c9b7e70fac1864 /src | |
parent | 7675fb23a0448448662567bf1d100e39bf7b5e65 (diff) |
Add pop_back() to GrAllocator and add unit test.
BUG=skia:2889
R=robertphillips@google.com
Author: bsalomon@google.com
Review URL: https://codereview.chromium.org/538183002
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrAllocator.h | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/gpu/GrAllocator.h b/src/gpu/GrAllocator.h index 933be9f655..37c123f793 100644 --- a/src/gpu/GrAllocator.h +++ b/src/gpu/GrAllocator.h @@ -61,6 +61,24 @@ public: } /** + * Remove the last item, only call if count() != 0 + */ + void pop_back() { + SkASSERT(fCount); + SkASSERT(fInsertionIndexInBlock > 0); + --fInsertionIndexInBlock; + --fCount; + if (0 == fInsertionIndexInBlock) { + // Never delete the first block + if (fBlocks.count() > 1) { + sk_free(fBlocks.back()); + fBlocks.pop_back(); + fInsertionIndexInBlock = fItemsPerBlock; + } + } + } + + /** * Removes all added items. */ void reset() { @@ -109,7 +127,6 @@ public: return (const char*)(fBlocks.back()) + (fInsertionIndexInBlock - 1) * fItemSize; } - /** * Iterates through the allocator. This is faster than using operator[] when walking linearly * through the allocator. @@ -240,6 +257,14 @@ public: } /** + * Remove the last item, only call if count() != 0 + */ + void pop_back() { + this->back().~T(); + fAllocator.pop_back(); + } + + /** * Removes all added items. */ void reset() { |