Bug 1267524 Part 4.1 - Add Reset() and rewrite methods for nsStyleSVGPaint.
Eliminate the explicit destructor / placement new calls in SetType().
MozReview-Commit-ID: 1CtjX1AEbFR
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -1380,29 +1380,57 @@ nsChangeHint nsStyleSVGReset::CalcDiffer
}
hint |= mMask.CalcDifference(aOther.mMask);
return hint;
}
// nsStyleSVGPaint implementation
+nsStyleSVGPaint::nsStyleSVGPaint(nsStyleSVGPaintType aType)
+ : mType(nsStyleSVGPaintType(0))
+ , mFallbackColor(NS_RGB(0, 0, 0))
+{
+ SetType(aType);
+}
+
+nsStyleSVGPaint::nsStyleSVGPaint(const nsStyleSVGPaint& aSource)
+ : mType(nsStyleSVGPaintType(0))
+ , mFallbackColor(NS_RGB(0, 0, 0))
+{
+ SetType(aSource.mType);
+
+ mFallbackColor = aSource.mFallbackColor;
+ if (mType == eStyleSVGPaintType_Server) {
+ mPaint.mPaintServer = aSource.mPaint.mPaintServer;
+ NS_IF_ADDREF(mPaint.mPaintServer);
+ } else {
+ mPaint.mColor = aSource.mPaint.mColor;
+ }
+}
+
nsStyleSVGPaint::~nsStyleSVGPaint()
{
- if (mType == eStyleSVGPaintType_Server) {
- NS_IF_RELEASE(mPaint.mPaintServer);
- }
+ Reset();
+}
+
+void
+nsStyleSVGPaint::Reset()
+{
+ SetType(nsStyleSVGPaintType(0));
}
void
nsStyleSVGPaint::SetType(nsStyleSVGPaintType aType)
{
if (mType == eStyleSVGPaintType_Server) {
- this->~nsStyleSVGPaint();
- new (this) nsStyleSVGPaint();
+ NS_IF_RELEASE(mPaint.mPaintServer);
+ mPaint.mPaintServer = nullptr;
+ } else {
+ mPaint.mColor = NS_RGB(0, 0, 0);
}
mType = aType;
}
nsStyleSVGPaint& nsStyleSVGPaint::operator=(const nsStyleSVGPaint& aOther)
{
if (this == &aOther)
return *this;
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -3235,18 +3235,20 @@ struct nsStyleSVGPaint
{
union {
nscolor mColor;
nsIURI *mPaintServer;
} mPaint;
nsStyleSVGPaintType mType;
nscolor mFallbackColor;
- nsStyleSVGPaint() : mType(nsStyleSVGPaintType(0)) { mPaint.mPaintServer = nullptr; }
+ explicit nsStyleSVGPaint(nsStyleSVGPaintType aType = nsStyleSVGPaintType(0));
+ nsStyleSVGPaint(const nsStyleSVGPaint& aSource);
~nsStyleSVGPaint();
+ void Reset();
void SetType(nsStyleSVGPaintType aType);
nsStyleSVGPaint& operator=(const nsStyleSVGPaint& aOther);
bool operator==(const nsStyleSVGPaint& aOther) const;
bool operator!=(const nsStyleSVGPaint& aOther) const {
return !(*this == aOther);
}
};