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

Unified Diff: include/core/SkTDArray.h

Issue 132313013: Revert of 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 e51f2cd008e5ad07f451377c3ebaedcd4421fdd2..67254ccc9a88fa93fe6489ea82bccb6efe8959e6 100644
--- a/include/core/SkTDArray.h
+++ b/include/core/SkTDArray.h
@@ -151,43 +151,25 @@
fCount = 0;
}
- /**
- * Sets the number of elements in the array.
- * If the array does not have space for count elements, it will increase
- * the storage allocated to some amount greater than that required.
- * It will never shrink the shrink the storage.
- */
void setCount(int count) {
- // TODO(mtklein): eliminate this method, setCountExact -> setCount
- SkASSERT(count >= 0);
if (count > fReserve) {
- resizeStorageToAtLeast(count);
- }
- fCount = count;
- }
-
- /**
- * Sets the number of elements in the array.
- * If the array does not have space for count elements, it will increase
- * the storage allocated to exactly the amount required, with no remaining
- * reserved space.
- * It will never shrink the shrink the storage.
- */
- void setCountExact(int count) {
- if (count > fReserve) {
- this->resizeStorageToExact(count);
- }
- fCount = count;
+ this->growBy(count - fCount);
+ } else {
+ fCount = count;
+ }
}
void setReserve(int reserve) {
if (reserve > fReserve) {
- resizeStorageToAtLeast(reserve);
+ SkASSERT(reserve > fCount);
+ int count = fCount;
+ this->growBy(reserve - fCount);
+ fCount = count;
}
}
T* prepend() {
- this->adjustCount(1);
+ this->growBy(1);
memmove(fArray + 1, fArray, (fCount - 1) * sizeof(T));
return fArray;
}
@@ -201,7 +183,7 @@
SkASSERT(src == NULL || fArray == NULL ||
src + count <= fArray || fArray + oldCount <= src);
- this->adjustCount(count);
+ this->growBy(count);
if (src) {
memcpy(fArray + oldCount, src, sizeof(T) * count);
}
@@ -222,7 +204,7 @@
SkASSERT(count);
SkASSERT(index <= fCount);
size_t oldCount = fCount;
- this->adjustCount(count);
+ this->growBy(count);
T* dst = fArray + index;
memmove(dst + count, dst, sizeof(T) * (oldCount - index));
if (src) {
@@ -374,43 +356,20 @@
int fReserve;
int fCount;
- /**
- * Adjusts the number of elements in the array.
- * This is the same as calling setCount(count() + delta).
- */
- void adjustCount(int delta) {
- setCount(fCount + delta);
- }
-
- /**
- * This resizes the storage to *exactly* count elements, growing or
- * shrinking the allocation as needed. It does not ASSERT anything about
- * the previous allocation size, or about fCount.
- *
- * note: does NOT modify fCount
- */
- void resizeStorageToExact(int count) {
- SkASSERT(count >= 0);
- fArray = (T*)sk_realloc_throw(fArray, count * sizeof(T));
-#ifdef SK_DEBUG
- fData = (ArrayT*)fArray;
-#endif
- fReserve = count;
- }
-
- /**
- * Increase the storage allocation such that it can hold (fCount + extra)
- * elements.
- * It never shrinks the allocation, and it may increase the allocation by
- * more than is strictly required, based on a private growth heuristic.
- *
- * note: does NOT modify fCount
- */
- void resizeStorageToAtLeast(int count) {
- SkASSERT(count > fReserve);
- int space = count + 4;
- space += space>>2;
- resizeStorageToExact(space);
+ void growBy(int extra) {
+ 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;
+ }
+ 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