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

Unified Diff: src/gpu/GrAllocator.h

Issue 538183002: Add pop_back() to GrAllocator and add unit test. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments and put local struct type in anonymous namespace 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/tests.gypi ('k') | tests/GrAllocatorTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrAllocator.h
diff --git a/src/gpu/GrAllocator.h b/src/gpu/GrAllocator.h
index 933be9f655aeb62c14c5d152cdd0d754c0cbf99d..37c123f7936c097558896eabfb9a349d2ced488f 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() {
« no previous file with comments | « gyp/tests.gypi ('k') | tests/GrAllocatorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698