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

Unified Diff: include/private/SkTemplates.h

Issue 2084213003: Make container classes in SkTemplates.h more consistent (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: break dependency Created 4 years, 6 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 | tests/TemplatesTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/private/SkTemplates.h
diff --git a/include/private/SkTemplates.h b/include/private/SkTemplates.h
index 7e2c19f09daa199486462e0410f64a79a58cce2c..01a8ec0c3bd90ddc9fcfb3bc0863f0db29b1693c 100644
--- a/include/private/SkTemplates.h
+++ b/include/private/SkTemplates.h
@@ -192,6 +192,7 @@ public:
(--iter)->~T();
}
+ SkASSERT(count >= 0);
if (fCount != count) {
if (fCount > kCount) {
// 'fArray' was allocated last time so free it now
@@ -267,7 +268,7 @@ public:
/** Allocates space for 'count' Ts. */
explicit SkAutoTMalloc(size_t count) {
- fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW);
+ fPtr = count ? (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW) : nullptr;
}
~SkAutoTMalloc() {
@@ -276,7 +277,11 @@ public:
/** Resize the memory area pointed to by the current ptr preserving contents. */
void realloc(size_t count) {
- fPtr = reinterpret_cast<T*>(sk_realloc_throw(fPtr, count * sizeof(T)));
+ if (count) {
+ fPtr = reinterpret_cast<T*>(sk_realloc_throw(fPtr, count * sizeof(T)));
+ } else {
+ this->reset(0);
+ }
}
/** Resize the memory area pointed to by the current ptr without preserving contents. */
@@ -326,8 +331,10 @@ public:
SkAutoSTMalloc(size_t count) {
if (count > kCount) {
fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW | SK_MALLOC_TEMP);
- } else {
+ } else if (count) {
fPtr = fTStorage;
+ } else {
+ fPtr = nullptr;
}
}
@@ -344,8 +351,10 @@ public:
}
if (count > kCount) {
fPtr = (T*)sk_malloc_throw(count * sizeof(T));
- } else {
+ } else if (count) {
fPtr = fTStorage;
+ } else {
+ fPtr = nullptr;
}
return fPtr;
}
@@ -377,8 +386,12 @@ public:
} else {
fPtr = (T*)sk_realloc_throw(fPtr, count * sizeof(T));
}
- } else if (fPtr != fTStorage) {
- fPtr = (T*)sk_realloc_throw(fPtr, count * sizeof(T));
+ } else if (count) {
+ if (fPtr != fTStorage) {
+ fPtr = (T*)sk_realloc_throw(fPtr, count * sizeof(T));
+ }
+ } else {
+ this->reset(0);
}
}
« no previous file with comments | « no previous file | tests/TemplatesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698