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

Side by Side Diff: src/core/SkVarAlloc.h

Issue 721313002: Deparameterize SkVarAlloc. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fixes: update unit test, remove unused header, start at 16 bytes Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « src/core/SkRecord.h ('k') | src/core/SkVarAlloc.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #ifndef SkVarAlloc_DEFINED 1 #ifndef SkVarAlloc_DEFINED
2 #define SkVarAlloc_DEFINED 2 #define SkVarAlloc_DEFINED
3 3
4 #include "SkTypes.h" 4 #include "SkTypes.h"
5 5
6 class SkVarAlloc : SkNoncopyable { 6 class SkVarAlloc : SkNoncopyable {
7 public: 7 public:
8 // SkVarAlloc will never allocate less than smallest bytes at a time. 8 SkVarAlloc();
9 // When it allocates a new block, it will be at least growth times bigger th an the last.
10 SkVarAlloc(size_t smallest, float growth);
11 ~SkVarAlloc(); 9 ~SkVarAlloc();
12 10
13 // Returns contiguous bytes aligned at least for pointers. You may pass SK_ MALLOC_THROW, etc. 11 // Returns contiguous bytes aligned at least for pointers. You may pass SK_ MALLOC_THROW, etc.
14 char* alloc(size_t bytes, unsigned sk_malloc_flags) { 12 char* alloc(size_t bytes, unsigned sk_malloc_flags) {
15 bytes = SkAlignPtr(bytes); 13 bytes = SkAlignPtr(bytes);
16 14
17 if (fByte + bytes > fLimit) { 15 if (bytes > fRemaining) {
18 this->makeSpace(bytes, sk_malloc_flags); 16 this->makeSpace(bytes, sk_malloc_flags);
19 } 17 }
20 SkASSERT(fByte + bytes <= fLimit); 18 SkASSERT(bytes <= fRemaining);
21 19
22 char* ptr = fByte; 20 char* ptr = fByte;
23 fByte += bytes; 21 fByte += bytes;
22 fRemaining -= bytes;
24 return ptr; 23 return ptr;
25 } 24 }
26 25
27 private: 26 private:
28 void makeSpace(size_t bytes, unsigned flags); 27 void makeSpace(size_t bytes, unsigned flags);
29 28
30 char* fByte; 29 char* fByte;
31 const char* fLimit; 30 unsigned fRemaining;
32 31 unsigned fLgMinSize;
33 unsigned fSmallest;
34 const float fGrowth;
35 32
36 struct Block; 33 struct Block;
37 Block* fBlock; 34 Block* fBlock;
38 }; 35 };
39 36
40 #endif//SkVarAlloc_DEFINED 37 #endif//SkVarAlloc_DEFINED
OLDNEW
« no previous file with comments | « src/core/SkRecord.h ('k') | src/core/SkVarAlloc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698