aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkString.cpp
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2016-02-07 18:42:54 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-07 18:42:54 -0800
commit9d55297f1fd1ed0f74277fd95b4c59608220aa77 (patch)
tree9c73024de69e737bb268984dfcbd02b20f06084f /src/core/SkString.cpp
parentccce0e02576100e1baaab6b18d91acaff624753e (diff)
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
Diffstat (limited to 'src/core/SkString.cpp')
-rw-r--r--src/core/SkString.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp
index b5655e0503..8ac5674474 100644
--- a/src/core/SkString.cpp
+++ b/src/core/SkString.cpp
@@ -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();