diff options
author | benjaminwagner <benjaminwagner@google.com> | 2016-02-02 16:01:39 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-02 16:01:39 -0800 |
commit | 67e8bd207261ed4a4b30c4e488a6a2b6baf04d7a (patch) | |
tree | 4914444176e82ce7473f3b0a7caf0fd0c678c1e7 /include/core/SkTypes.h | |
parent | 8870e94fe38dc2cd73e0603b5facc4af78b5be83 (diff) |
Revert of Move Google3-specific stack limitation logic to template classes. Remove #ifdefs in other files. (patchset #2 id:50001 of https://codereview.chromium.org/1656143003/ )
Reason for revert:
See https://codereview.chromium.org/1665603002
Original issue's description:
> Move Google3-specific stack limitation logic to template classes. Remove #ifdefs in other files.
>
> Does not change the public API.
>
> TBR=reed
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1656143003
>
> Committed: https://skia.googlesource.com/skia/+/c92159c8250c62cc47b7b63686538d61d54d2835
TBR=mtklein@google.com,reed@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Review URL: https://codereview.chromium.org/1666503002
Diffstat (limited to 'include/core/SkTypes.h')
-rw-r--r-- | include/core/SkTypes.h | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index 4592168bd4..0d31efc6cc 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -606,16 +606,17 @@ private: #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. + * 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 kSizeRequested> class SkAutoSMalloc : SkNoncopyable { +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 @@ public: } /** - * 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 @@ public: } /** - * 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 @@ public: } /** - * 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 @@ public: } 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. |