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

Side by Side Diff: include/core/SkRefCnt.h

Issue 1767983002: Fix behavior of sk_sp::reset() and add unittest. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use unique() correctly Created 4 years, 9 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 | « no previous file | tests/RefCntTest.cpp » ('j') | 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 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkRefCnt_DEFINED 8 #ifndef SkRefCnt_DEFINED
9 #define SkRefCnt_DEFINED 9 #define SkRefCnt_DEFINED
10 10
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 bool operator!() const { return this->get() == nullptr; } 331 bool operator!() const { return this->get() == nullptr; }
332 332
333 T* get() const { return fPtr; } 333 T* get() const { return fPtr; }
334 T* operator->() const { return fPtr; } 334 T* operator->() const { return fPtr; }
335 335
336 /** 336 /**
337 * Adopt the new bare pointer, and call unref() on any previously held obje ct (if not null). 337 * Adopt the new bare pointer, and call unref() on any previously held obje ct (if not null).
338 * No call to ref() will be made. 338 * No call to ref() will be made.
339 */ 339 */
340 void reset(T* ptr = nullptr) { 340 void reset(T* ptr = nullptr) {
341 if (fPtr != ptr) { 341 SkSafeUnref(fPtr);
342 SkSafeUnref(fPtr); 342 fPtr = ptr;
343 fPtr = ptr;
344 }
345 } 343 }
346 344
347 /** 345 /**
348 * Return the bare pointer, and set the internal object pointer to nullptr. 346 * Return the bare pointer, and set the internal object pointer to nullptr.
349 * The caller must assume ownership of the object, and manage its reference count directly. 347 * The caller must assume ownership of the object, and manage its reference count directly.
350 * No call to unref() will be made. 348 * No call to unref() will be made.
351 */ 349 */
352 T* SK_WARN_UNUSED_RESULT release() { 350 T* SK_WARN_UNUSED_RESULT release() {
353 T* ptr = fPtr; 351 T* ptr = fPtr;
354 fPtr = nullptr; 352 fPtr = nullptr;
355 return ptr; 353 return ptr;
356 } 354 }
357 355
358 private: 356 private:
359 T* fPtr; 357 T* fPtr;
360 }; 358 };
361 359
362 template <typename T, typename... Args> 360 template <typename T, typename... Args>
363 sk_sp<T> sk_make_sp(Args&&... args) { 361 sk_sp<T> sk_make_sp(Args&&... args) {
364 return sk_sp<T>(new T(std::forward<Args>(args)...)); 362 return sk_sp<T>(new T(std::forward<Args>(args)...));
365 } 363 }
366 364
367 #endif 365 #endif
OLDNEW
« no previous file with comments | « no previous file | tests/RefCntTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698