Make SkString movable.

This adds a move constructor and move assignment to SkString. This
allows elision of atomic increments and decrements on the fRec.

TBR=reed
Already agreed that moving is good.

Review URL: https://codereview.chromium.org/1672123002
This commit is contained in:
bungeman 2016-02-07 18:42:54 -08:00 committed by Commit bot
parent ccce0e0257
commit 9d55297f1f
2 changed files with 18 additions and 0 deletions

View File

@ -126,6 +126,7 @@ public:
explicit SkString(const char text[]);
SkString(const char text[], size_t len);
SkString(const SkString&);
SkString(SkString&&);
~SkString();
bool isEmpty() const { return 0 == fRec->fLength; }
@ -172,6 +173,7 @@ public:
// these methods edit the string
SkString& operator=(const SkString&);
SkString& operator=(SkString&&);
SkString& operator=(const char text[]);
char* writable_str();

View File

@ -275,6 +275,13 @@ SkString::SkString(const SkString& src) {
fRec = RefRec(src.fRec);
}
SkString::SkString(SkString&& src) {
src.validate();
fRec = src.fRec;
src.fRec = const_cast<Rec*>(&gEmptyRec);
}
SkString::~SkString() {
this->validate();
@ -310,6 +317,15 @@ SkString& SkString::operator=(const SkString& src) {
return *this;
}
SkString& SkString::operator=(SkString&& src) {
this->validate();
if (fRec != src.fRec) {
this->swap(src);
}
return *this;
}
SkString& SkString::operator=(const char text[]) {
this->validate();