aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar herb <herb@google.com>2016-11-03 07:34:15 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-11-03 07:34:15 -0700
commite736e0c2d52a29a3b88a29ab39b3a90a5a2443a0 (patch)
treedbff837c6a7de842ffd1fbe0d9a0247e25d86ee4
parent42cb490f37c8162aa7b25d9b932dee8a7eddc3c7 (diff)
Try to use only std::aligned_storage. This does not change the API.
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2468243002 TBR=reed@google.com Review-Url: https://codereview.chromium.org/2468243002
-rw-r--r--include/core/SkPostConfig.h9
-rw-r--r--src/core/SkLinearBitmapPipeline.h17
-rw-r--r--src/core/SkSmallAllocator.h12
3 files changed, 12 insertions, 26 deletions
diff --git a/include/core/SkPostConfig.h b/include/core/SkPostConfig.h
index 1b1cb3e751..c34397cde6 100644
--- a/include/core/SkPostConfig.h
+++ b/include/core/SkPostConfig.h
@@ -77,15 +77,6 @@
# endif
#endif
-// As usual, there are two ways to increase alignment... the MSVC way and the everyone-else way.
-#ifndef SK_STRUCT_ALIGN
- #ifdef _MSC_VER
- #define SK_STRUCT_ALIGN(N) __declspec(align(N))
- #else
- #define SK_STRUCT_ALIGN(N) __attribute__((aligned(N)))
- #endif
-#endif
-
#if defined(_MSC_VER) && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
#define SK_VECTORCALL __vectorcall
#elif defined(SK_CPU_ARM32) && defined(SK_ARM_HAS_NEON)
diff --git a/src/core/SkLinearBitmapPipeline.h b/src/core/SkLinearBitmapPipeline.h
index 91b573df5d..d9fa97522e 100644
--- a/src/core/SkLinearBitmapPipeline.h
+++ b/src/core/SkLinearBitmapPipeline.h
@@ -57,6 +57,9 @@ public:
void shadeSpan4f(int x, int y, SkPM4f* dst, int count);
void blitSpan(int32_t x, int32_t y, void* dst, int count);
+ template <size_t N>
+ using Storage = typename std::aligned_storage<N, 16>::type;
+
template<typename Base, size_t kSize, typename Next = void>
class Stage {
public:
@@ -84,11 +87,8 @@ public:
private:
std::function<void (Next*, void*)> fStageCloner;
- struct SK_STRUCT_ALIGN(16) Space {
- char space[kSize];
- };
- bool fIsInitialized;
- mutable Space fSpace;
+ mutable Storage<kSize> fSpace;
+ bool fIsInitialized;
};
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -116,11 +116,8 @@ public:
Base& operator*() const { return *(this->get()); }
private:
- struct SK_STRUCT_ALIGN(16) Space {
- char space[kSize];
- };
- mutable Space fSpace;
- bool fIsInitialized;
+ mutable Storage<kSize> fSpace;
+ bool fIsInitialized;
};
diff --git a/src/core/SkSmallAllocator.h b/src/core/SkSmallAllocator.h
index 9095fa57fc..b39e359d52 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*>(bytes() + fStorageUsed);
fStorageUsed += storageRequired;
}
rec->fKillProc = DestroyT<T>;
@@ -129,13 +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];
- };
+ char* bytes() { return reinterpret_cast<char*>(&fStorage); }
+
+ using Storage = typename std::aligned_storage<kTotalBytes, 16>::type;
- Storage fStorage;
+ Storage fStorage[kMaxObjects];
// Number of bytes used so far.
size_t fStorageUsed;
uint32_t fNumObjects;