Make SkPaint movable.

This adds a move constructor and move assignment to SkPaint. This
allows elision of atomic increments and decrements on the reference
counted fields.

Review URL: https://codereview.chromium.org/1676843002
This commit is contained in:
bungeman 2016-02-07 14:37:23 -08:00 committed by Commit bot
parent 4e79f33452
commit ccce0e0257
2 changed files with 62 additions and 0 deletions

View File

@ -52,9 +52,11 @@ class SK_API SkPaint {
public:
SkPaint();
SkPaint(const SkPaint& paint);
SkPaint(SkPaint&& paint);
~SkPaint();
SkPaint& operator=(const SkPaint&);
SkPaint& operator=(SkPaint&&);
/** operator== may give false negatives: two paints that draw equivalently
may return false. It will never give false positives: two paints that

View File

@ -101,6 +101,33 @@ SkPaint::SkPaint(const SkPaint& src) {
#undef REF_COPY
}
SkPaint::SkPaint(SkPaint&& src) {
#define MOVE(field) field = std::move(src.field)
#define REF_MOVE(field) field = src.field; src.field = nullptr
REF_MOVE(fTypeface);
REF_MOVE(fPathEffect);
REF_MOVE(fShader);
REF_MOVE(fXfermode);
REF_MOVE(fMaskFilter);
REF_MOVE(fColorFilter);
REF_MOVE(fRasterizer);
REF_MOVE(fLooper);
REF_MOVE(fImageFilter);
REF_MOVE(fAnnotation);
MOVE(fTextSize);
MOVE(fTextScaleX);
MOVE(fTextSkewX);
MOVE(fColor);
MOVE(fWidth);
MOVE(fMiterLimit);
MOVE(fBitfields);
#undef MOVE
#undef REF_MOVE
}
SkPaint::~SkPaint() {
SkSafeUnref(fTypeface);
SkSafeUnref(fPathEffect);
@ -147,6 +174,39 @@ SkPaint& SkPaint::operator=(const SkPaint& src) {
#undef REF_COPY
}
SkPaint& SkPaint::operator=(SkPaint&& src) {
if (this == &src) {
return *this;
}
#define MOVE(field) field = std::move(src.field)
#define REF_MOVE(field) SkSafeUnref(field); field = src.field; src.field = nullptr
REF_MOVE(fTypeface);
REF_MOVE(fPathEffect);
REF_MOVE(fShader);
REF_MOVE(fXfermode);
REF_MOVE(fMaskFilter);
REF_MOVE(fColorFilter);
REF_MOVE(fRasterizer);
REF_MOVE(fLooper);
REF_MOVE(fImageFilter);
REF_MOVE(fAnnotation);
MOVE(fTextSize);
MOVE(fTextScaleX);
MOVE(fTextSkewX);
MOVE(fColor);
MOVE(fWidth);
MOVE(fMiterLimit);
MOVE(fBitfields);
return *this;
#undef MOVE
#undef REF_MOVE
}
bool operator==(const SkPaint& a, const SkPaint& b) {
#define EQUAL(field) (a.field == b.field)
return EQUAL(fTypeface)