aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrAllocator.h
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-09-05 06:13:43 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-09-05 06:13:43 -0700
commita1ae66d252edf6da932caed1fe43d11216e56c0e (patch)
tree8247f3d0f63830970f71bd1bc5c9b7e70fac1864 /src/gpu/GrAllocator.h
parent7675fb23a0448448662567bf1d100e39bf7b5e65 (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/gpu/GrAllocator.h')
-rw-r--r--src/gpu/GrAllocator.h27
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() {