diff options
author | 2016-11-04 08:41:01 -0700 | |
---|---|---|
committer | 2016-11-04 08:41:01 -0700 | |
commit | 12ae597ef54c35e9c447f5f52ecbc153503e8b73 (patch) | |
tree | e284d94b5c97fc67684791d393bc80a176f957a9 /src/core | |
parent | bab7945563c2b01f882b37a22b7b3c7ff0e8a3d8 (diff) |
Use alignas to force alignment.
Using alignas reduces code and platform specific macros.
Use alignas instead of std::aligned_storage because it is unimplemneted
in MSVC 2015.
Here is the bug from MS:
https://connect.microsoft.com/VisualStudio/feedback/details/1559873/std-aligned-storage-cannot-align-type-with-16-byte
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2468243002
TBR=reed@google.com
Review-Url: https://codereview.chromium.org/2473143002
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkLinearBitmapPipeline.h | 20 | ||||
-rw-r--r-- | src/core/SkSmallAllocator.h | 16 |
2 files changed, 12 insertions, 24 deletions
diff --git a/src/core/SkLinearBitmapPipeline.h b/src/core/SkLinearBitmapPipeline.h index 91b573df5d..3abdb8014a 100644 --- a/src/core/SkLinearBitmapPipeline.h +++ b/src/core/SkLinearBitmapPipeline.h @@ -78,17 +78,14 @@ public: // the pipeline on a new sampler. Base* cloneStageTo(Next* next, Stage* cloneToStage) const; - Base* get() const { return reinterpret_cast<Base*>(&fSpace); } + Base* get() const { return reinterpret_cast<Base*>(fSpace); } Base* operator->() const { return this->get(); } Base& operator*() const { return *(this->get()); } private: std::function<void (Next*, void*)> fStageCloner; - struct SK_STRUCT_ALIGN(16) Space { - char space[kSize]; - }; - bool fIsInitialized; - mutable Space fSpace; + alignas(16) mutable char fSpace[kSize]; + bool fIsInitialized; }; /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -111,16 +108,13 @@ public: fIsInitialized = true; } - Base* get() const { return reinterpret_cast<Base*>(&fSpace); } + Base* get() const { return reinterpret_cast<Base*>(fSpace); } Base* operator->() const { return this->get(); } Base& operator*() const { return *(this->get()); } private: - struct SK_STRUCT_ALIGN(16) Space { - char space[kSize]; - }; - mutable Space fSpace; - bool fIsInitialized; + alignas(16) mutable char fSpace[kSize]; + bool fIsInitialized; }; @@ -134,7 +128,7 @@ public: using MatrixStage = Stage<PointProcessorInterface, 160, PointProcessorInterface>; using TileStage = Stage<PointProcessorInterface, 160, SampleProcessorInterface>; using SampleStage = Stage<SampleProcessorInterface, 160, BlendProcessorInterface>; - using BlenderStage = Stage<BlendProcessorInterface, 40>; + using BlenderStage = Stage<BlendProcessorInterface, 48>; using Accessor = PolyMemory<PixelAccessorInterface, 64>; private: diff --git a/src/core/SkSmallAllocator.h b/src/core/SkSmallAllocator.h index 9095fa57fc..67afe75691 100644 --- a/src/core/SkSmallAllocator.h +++ b/src/core/SkSmallAllocator.h @@ -93,7 +93,7 @@ public: // There is space in fStorage. rec->fStorageSize = storageRequired; rec->fHeapStorage = nullptr; - rec->fObj = static_cast<void*>(fStorage.fBytes + fStorageUsed); + rec->fObj = static_cast<void*>(fStorage + fStorageUsed); fStorageUsed += storageRequired; } rec->fKillProc = DestroyT<T>; @@ -129,17 +129,11 @@ private: static_cast<T*>(ptr)->~T(); } - struct SK_STRUCT_ALIGN(16) Storage { - // we add kMaxObjects * 15 to account for the worst-case slop, where each allocation wasted - // 15 bytes (due to forcing each to be 16-byte aligned) - char fBytes[kTotalBytes + kMaxObjects * 15]; - }; - - Storage fStorage; + alignas(16) char fStorage[kTotalBytes]; // Number of bytes used so far. - size_t fStorageUsed; - uint32_t fNumObjects; - Rec fRecs[kMaxObjects]; + size_t fStorageUsed; + uint32_t fNumObjects; + Rec fRecs[kMaxObjects]; }; #endif // SkSmallAllocator_DEFINED |