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

Unified Diff: src/core/SkLinearBitmapPipeline.h

Issue 1752433002: Simplify the poly union. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: work around clang compiler. Created 4 years, 10 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/core/SkLinearBitmapPipeline.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkLinearBitmapPipeline.h
diff --git a/src/core/SkLinearBitmapPipeline.h b/src/core/SkLinearBitmapPipeline.h
index 3d5dd31df34d533531ac87473f092e75cd6637d5..c65b7538aa3a2f6962ce11f6005e3c28553f81f8 100644
--- a/src/core/SkLinearBitmapPipeline.h
+++ b/src/core/SkLinearBitmapPipeline.h
@@ -29,9 +29,13 @@ public:
template<typename Base, size_t kSize>
class PolymorphicUnion {
public:
- PolymorphicUnion() {}
+ PolymorphicUnion() : fIsInitialized{false} {}
- ~PolymorphicUnion() { get()->~Base(); }
+ ~PolymorphicUnion() {
+ if (fIsInitialized) {
+ get()->~Base();
+ }
+ }
template<typename Variant, typename... Args>
void Initialize(Args&&... args) {
@@ -39,6 +43,7 @@ public:
"Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSpace));
new(&fSpace) Variant(std::forward<Args>(args)...);
+ fIsInitialized = true;
};
Base* get() const { return reinterpret_cast<Base*>(&fSpace); }
@@ -49,6 +54,7 @@ public:
struct SK_STRUCT_ALIGN(16) Space {
char space[kSize];
};
+ bool fIsInitialized;
mutable Space fSpace;
};
« no previous file with comments | « no previous file | src/core/SkLinearBitmapPipeline.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698