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
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; }
// these methods edit the string
SkString& operator=(const SkString&);
+ SkString& operator=(SkString&&);
SkString& operator=(const char text[]);
char* writable_str();
fRec = RefRec(src.fRec);
}
+SkString::SkString(SkString&& src) {
+ src.validate();
+
+ fRec = src.fRec;
+ src.fRec = const_cast<Rec*>(&gEmptyRec);
+}
+
SkString::~SkString() {
this->validate();
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();