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:
parent
ccce0e0257
commit
9d55297f1f
@ -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();
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user