Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: src/core/SkString.cpp

Issue 1672123002: Make SkString movable. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Don't need 'this' on 'f' fields. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkString.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkAtomics.h" 10 #include "SkAtomics.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 SkString::SkString(const char text[], size_t len) { 268 SkString::SkString(const char text[], size_t len) {
269 fRec = AllocRec(text, len); 269 fRec = AllocRec(text, len);
270 } 270 }
271 271
272 SkString::SkString(const SkString& src) { 272 SkString::SkString(const SkString& src) {
273 src.validate(); 273 src.validate();
274 274
275 fRec = RefRec(src.fRec); 275 fRec = RefRec(src.fRec);
276 } 276 }
277 277
278 SkString::SkString(SkString&& src) {
279 src.validate();
280
281 fRec = src.fRec;
282 src.fRec = const_cast<Rec*>(&gEmptyRec);
283 }
284
278 SkString::~SkString() { 285 SkString::~SkString() {
279 this->validate(); 286 this->validate();
280 287
281 if (fRec->fLength) { 288 if (fRec->fLength) {
282 SkASSERT(fRec->fRefCnt > 0); 289 SkASSERT(fRec->fRefCnt > 0);
283 if (sk_atomic_dec(&fRec->fRefCnt) == 1) { 290 if (sk_atomic_dec(&fRec->fRefCnt) == 1) {
284 sk_free(fRec); 291 sk_free(fRec);
285 } 292 }
286 } 293 }
287 } 294 }
(...skipping 15 matching lines...) Expand all
303 SkString& SkString::operator=(const SkString& src) { 310 SkString& SkString::operator=(const SkString& src) {
304 this->validate(); 311 this->validate();
305 312
306 if (fRec != src.fRec) { 313 if (fRec != src.fRec) {
307 SkString tmp(src); 314 SkString tmp(src);
308 this->swap(tmp); 315 this->swap(tmp);
309 } 316 }
310 return *this; 317 return *this;
311 } 318 }
312 319
320 SkString& SkString::operator=(SkString&& src) {
321 this->validate();
322
323 if (fRec != src.fRec) {
324 this->swap(src);
325 }
326 return *this;
327 }
328
313 SkString& SkString::operator=(const char text[]) { 329 SkString& SkString::operator=(const char text[]) {
314 this->validate(); 330 this->validate();
315 331
316 SkString tmp(text); 332 SkString tmp(text);
317 this->swap(tmp); 333 this->swap(tmp);
318 334
319 return *this; 335 return *this;
320 } 336 }
321 337
322 void SkString::reset() { 338 void SkString::reset() {
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 str += strspn(str, delimiters); 666 str += strspn(str, delimiters);
651 } else { 667 } else {
652 // Skip one delimiter. 668 // Skip one delimiter.
653 str += 1; 669 str += 1;
654 } 670 }
655 } 671 }
656 } 672 }
657 673
658 #undef VSNPRINTF 674 #undef VSNPRINTF
659 #undef SNPRINTF 675 #undef SNPRINTF
OLDNEW
« no previous file with comments | « include/core/SkString.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698