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

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

Issue 2473143002: Use alignas to force alignment. (Closed)
Patch Set: Remove comment. Created 4 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/SkLinearBitmapPipeline.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google, Inc 2 * Copyright 2014 Google, Inc
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkSmallAllocator_DEFINED 8 #ifndef SkSmallAllocator_DEFINED
9 #define SkSmallAllocator_DEFINED 9 #define SkSmallAllocator_DEFINED
10 10
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // and storage remaining is 3392. Increasing the base storage 86 // and storage remaining is 3392. Increasing the base storage
87 // causes google 3 tests to fail. 87 // causes google 3 tests to fail.
88 88
89 rec->fStorageSize = 0; 89 rec->fStorageSize = 0;
90 rec->fHeapStorage = sk_malloc_throw(storageRequired); 90 rec->fHeapStorage = sk_malloc_throw(storageRequired);
91 rec->fObj = static_cast<void*>(rec->fHeapStorage); 91 rec->fObj = static_cast<void*>(rec->fHeapStorage);
92 } else { 92 } else {
93 // There is space in fStorage. 93 // There is space in fStorage.
94 rec->fStorageSize = storageRequired; 94 rec->fStorageSize = storageRequired;
95 rec->fHeapStorage = nullptr; 95 rec->fHeapStorage = nullptr;
96 rec->fObj = static_cast<void*>(fStorage.fBytes + fStorageUsed); 96 rec->fObj = static_cast<void*>(fStorage + fStorageUsed);
97 fStorageUsed += storageRequired; 97 fStorageUsed += storageRequired;
98 } 98 }
99 rec->fKillProc = DestroyT<T>; 99 rec->fKillProc = DestroyT<T>;
100 fNumObjects++; 100 fNumObjects++;
101 return rec->fObj; 101 return rec->fObj;
102 } 102 }
103 103
104 /* 104 /*
105 * Free the memory reserved last without calling the destructor. 105 * Free the memory reserved last without calling the destructor.
106 * Can be used in a nested way, i.e. after reserving A and B, calling 106 * Can be used in a nested way, i.e. after reserving A and B, calling
(...skipping 15 matching lines...) Expand all
122 void* fHeapStorage; 122 void* fHeapStorage;
123 void (*fKillProc)(void*); 123 void (*fKillProc)(void*);
124 }; 124 };
125 125
126 // Used to call the destructor for allocated objects. 126 // Used to call the destructor for allocated objects.
127 template<typename T> 127 template<typename T>
128 static void DestroyT(void* ptr) { 128 static void DestroyT(void* ptr) {
129 static_cast<T*>(ptr)->~T(); 129 static_cast<T*>(ptr)->~T();
130 } 130 }
131 131
132 struct SK_STRUCT_ALIGN(16) Storage { 132 alignas(16) char fStorage[kTotalBytes];
133 // we add kMaxObjects * 15 to account for the worst-case slop, where eac h allocation wasted
134 // 15 bytes (due to forcing each to be 16-byte aligned)
135 char fBytes[kTotalBytes + kMaxObjects * 15];
136 };
137
138 Storage fStorage;
139 // Number of bytes used so far. 133 // Number of bytes used so far.
140 size_t fStorageUsed; 134 size_t fStorageUsed;
141 uint32_t fNumObjects; 135 uint32_t fNumObjects;
142 Rec fRecs[kMaxObjects]; 136 Rec fRecs[kMaxObjects];
143 }; 137 };
144 138
145 #endif // SkSmallAllocator_DEFINED 139 #endif // SkSmallAllocator_DEFINED
OLDNEW
« no previous file with comments | « src/core/SkLinearBitmapPipeline.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698