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

Unified Diff: include/core/SkTDArray.h

Issue 150663014: Change growth function for SkWriter32 (Closed) Base URL: https://skia.googlesource.com/skia.git@no_external_test
Patch Set: Created 6 years, 10 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 | « no previous file | src/core/SkWriter32.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkTDArray.h
diff --git a/include/core/SkTDArray.h b/include/core/SkTDArray.h
index 67254ccc9a88fa93fe6489ea82bccb6efe8959e6..a9369192a7521761c84b10b9e69f0539d5d2b1c0 100644
--- a/include/core/SkTDArray.h
+++ b/include/core/SkTDArray.h
@@ -159,6 +159,13 @@ public:
}
}
+ void setCountExact(int count) {
+ if (count > fReserve) {
+ this->growTo(count);
+ }
+ fCount = count;
+ }
+
void setReserve(int reserve) {
if (reserve > fReserve) {
SkASSERT(reserve > fCount);
@@ -356,18 +363,20 @@ private:
int fReserve;
int fCount;
+ void growTo(int size) {
reed1 2014/02/07 15:37:49 /** * This resizes the storage to *exactly* size
iancottrell 2014/02/07 16:54:15 Done.
+ fArray = (T*)sk_realloc_throw(fArray, size * sizeof(T));
+#ifdef SK_DEBUG
+ fData = (ArrayT*)fArray;
+#endif
+ fReserve = size;
+ }
+
void growBy(int extra) {
reed1 2014/02/07 15:37:49 /** * Increase the storage allocation such it can
iancottrell 2014/02/07 16:54:15 Done.
SkASSERT(extra);
if (fCount + extra > fReserve) {
int size = fCount + extra + 4;
- size += size >> 2;
-
- fArray = (T*)sk_realloc_throw(fArray, size * sizeof(T));
-#ifdef SK_DEBUG
- fData = (ArrayT*)fArray;
-#endif
- fReserve = size;
+ growTo(size + (size >> 2));
}
fCount += extra;
}
« no previous file with comments | « no previous file | src/core/SkWriter32.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698