Index: include/core/SkTypes.h |
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h |
index 4592168bd4d6da020179236511f439cd5cd30937..0d31efc6ccf7dd904dd7232b094aedaddbbc6870 100644 |
--- a/include/core/SkTypes.h |
+++ b/include/core/SkTypes.h |
@@ -606,16 +606,17 @@ |
#define SkAutoMalloc(...) SK_REQUIRE_LOCAL_VAR(SkAutoMalloc) |
/** |
- * Manage an allocated block of memory. If the requested size is <= kSizeRequested (or slightly |
- * more), then the allocation will come from the stack rather than the heap. This object is the |
- * sole manager of the lifetime of the block, so the caller must not call sk_free() or delete on |
- * the block. |
- */ |
-template <size_t kSizeRequested> class SkAutoSMalloc : SkNoncopyable { |
+ * Manage an allocated block of memory. If the requested size is <= kSize, then |
+ * the allocation will come from the stack rather than the heap. This object |
+ * is the sole manager of the lifetime of the block, so the caller must not |
+ * call sk_free() or delete on the block. |
+ */ |
+template <size_t kSize> class SkAutoSMalloc : SkNoncopyable { |
public: |
/** |
- * Creates initially empty storage. get() returns a ptr, but it is to a zero-byte allocation. |
- * Must call reset(size) to return an allocated block. |
+ * Creates initially empty storage. get() returns a ptr, but it is to |
+ * a zero-byte allocation. Must call reset(size) to return an allocated |
+ * block. |
*/ |
SkAutoSMalloc() { |
fPtr = fStorage; |
@@ -623,8 +624,9 @@ |
} |
/** |
- * Allocate a block of the specified size. If size <= kSizeRequested (or slightly more), then |
- * the allocation will come from the stack, otherwise it will be dynamically allocated. |
+ * Allocate a block of the specified size. If size <= kSize, then the |
+ * allocation will come from the stack, otherwise it will be dynamically |
+ * allocated. |
*/ |
explicit SkAutoSMalloc(size_t size) { |
fPtr = fStorage; |
@@ -633,8 +635,8 @@ |
} |
/** |
- * Free the allocated block (if any). If the block was small enough to have been allocated on |
- * the stack, then this does nothing. |
+ * Free the allocated block (if any). If the block was small enought to |
+ * have been allocated on the stack (size <= kSize) then this does nothing. |
*/ |
~SkAutoSMalloc() { |
if (fPtr != (void*)fStorage) { |
@@ -643,16 +645,18 @@ |
} |
/** |
- * Return the allocated block. May return non-null even if the block is of zero size. Since |
- * this may be on the stack or dynamically allocated, the caller must not call sk_free() on it, |
- * but must rely on SkAutoSMalloc to manage it. |
+ * Return the allocated block. May return non-null even if the block is |
+ * of zero size. Since this may be on the stack or dynamically allocated, |
+ * the caller must not call sk_free() on it, but must rely on SkAutoSMalloc |
+ * to manage it. |
*/ |
void* get() const { return fPtr; } |
/** |
- * Return a new block of the requested size, freeing (as necessary) any previously allocated |
- * block. As with the constructor, if size <= kSizeRequested (or slightly more) then the return |
- * block may be allocated locally, rather than from the heap. |
+ * Return a new block of the requested size, freeing (as necessary) any |
+ * previously allocated block. As with the constructor, if size <= kSize |
+ * then the return block may be allocated locally, rather than from the |
+ * heap. |
*/ |
void* reset(size_t size, |
SkAutoMalloc::OnShrink shrink = SkAutoMalloc::kAlloc_OnShrink, |
@@ -682,20 +686,9 @@ |
} |
private: |
- // Align up to 32 bits. |
- static const size_t kSizeAlign4 = SkAlign4(kSizeRequested); |
-#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 kMaxBytes = 4 * 1024; |
- static const size_t kSize = kSizeRequested > kMaxBytes ? kMaxBytes : kSizeAlign4; |
-#else |
- static const size_t kSize = kSizeAlign4; |
-#endif |
- |
void* fPtr; |
size_t fSize; // can be larger than the requested size (see kReuse) |
- uint32_t fStorage[kSize >> 2]; |
+ uint32_t fStorage[(kSize + 3) >> 2]; |
}; |
// Can't guard the constructor because it's a template class. |