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

Unified Diff: include/private/SkTemplates.h

Issue 1656143003: Move Google3-specific stack limitation logic to template classes. Remove #ifdefs in other files. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 11 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
Index: include/private/SkTemplates.h
diff --git a/include/private/SkTemplates.h b/include/private/SkTemplates.h
index 496cf427337664d82ed499412e67168af14f8f5b..c63bfdabe19f9ea34721212e3f4af22d1cb89aed 100644
--- a/include/private/SkTemplates.h
+++ b/include/private/SkTemplates.h
@@ -195,13 +195,13 @@ public:
}
if (fCount != count) {
- if (fCount > N) {
+ if (fCount > N_ADJ) {
mtklein 2016/02/02 03:04:29 Ditto here. It just seems easy to accidentally us
dogben 2016/02/02 19:39:34 Done. I made the naming consistent with SkAutoSMal
// 'fArray' was allocated last time so free it now
SkASSERT((T*) fStorage != fArray);
sk_free(fArray);
}
- if (count > N) {
+ if (count > N_ADJ) {
const uint64_t size64 = sk_64_mul(count, sizeof(T));
const size_t size = static_cast<size_t>(size64);
if (size != size64) {
@@ -240,10 +240,19 @@ public:
}
private:
+#if defined(GOOGLE3)
+ // Stack frame size is limited for GOOGLE3. 4k is less than the actual max, but some functions
+ // have multiple large stack allocations.
+ static const int MAX_BYTES = 4 * 1024;
+ static const int N_ADJ = N * sizeof(T) > MAX_BYTES ? MAX_BYTES / sizeof(T) : N;
+#else
+ static const int N_ADJ = N;
+#endif
+
int fCount;
T* fArray;
// since we come right after fArray, fStorage should be properly aligned
- char fStorage[N * sizeof(T)];
+ char fStorage[N_ADJ * sizeof(T)];
};
/** Manages an array of T elements, freeing the array in the destructor.
@@ -322,7 +331,7 @@ public:
SkAutoSTMalloc() : fPtr(fTStorage) {}
SkAutoSTMalloc(size_t count) {
- if (count > N) {
+ if (count > N_ADJ) {
fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW | SK_MALLOC_TEMP);
} else {
fPtr = fTStorage;
@@ -340,7 +349,7 @@ public:
if (fPtr != fTStorage) {
sk_free(fPtr);
}
- if (count > N) {
+ if (count > N_ADJ) {
fPtr = (T*)sk_malloc_throw(count * sizeof(T));
} else {
fPtr = fTStorage;
@@ -368,10 +377,10 @@ public:
// Reallocs the array, can be used to shrink the allocation. Makes no attempt to be intelligent
void realloc(size_t count) {
- if (count > N) {
+ if (count > N_ADJ) {
if (fPtr == fTStorage) {
fPtr = (T*)sk_malloc_throw(count * sizeof(T));
- memcpy(fPtr, fTStorage, N * sizeof(T));
+ memcpy(fPtr, fTStorage, N_ADJ * sizeof(T));
} else {
fPtr = (T*)sk_realloc_throw(fPtr, count * sizeof(T));
}
@@ -381,9 +390,20 @@ public:
}
private:
+ // Since we use uint32_t storage, we might be able to get more elements for free.
+ static const size_t N_WITH_PADDING = (((N*sizeof(T) + 3) >> 2) << 2) / sizeof(T);
+#if defined(GOOGLE3)
+ // Stack frame size is limited for GOOGLE3. 4k is less than the actual max, but some functions
+ // have multiple large stack allocations.
+ static const size_t MAX_BYTES = 4 * 1024;
+ static const size_t N_ADJ = N * sizeof(T) > MAX_BYTES ? MAX_BYTES / sizeof(T) : N_WITH_PADDING;
+#else
+ static const size_t N_ADJ = N_WITH_PADDING;
+#endif
+
T* fPtr;
union {
- uint32_t fStorage32[(N*sizeof(T) + 3) >> 2];
+ uint32_t fStorage32[(N_ADJ*sizeof(T) + 3) >> 2];
T fTStorage[1]; // do NOT want to invoke T::T()
};
};
« include/core/SkTypes.h ('K') | « include/core/SkTypes.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698