From 1fd201b9dfc739b7a615fdc1eb64dbe136e7cf76 Mon Sep 17 00:00:00 2001 From: "bungeman@google.com" Date: Wed, 22 Aug 2012 18:56:56 +0000 Subject: [PATCH] SkRef for expressions. https://codereview.appspot.com/6475045/ git-svn-id: http://skia.googlecode.com/svn/trunk@5238 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/core/SkRefCnt.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h index 32e41db..f527ebe 100644 --- a/include/core/SkRefCnt.h +++ b/include/core/SkRefCnt.h @@ -117,12 +117,21 @@ private: } while (0) -/** Check if the argument is non-null, and if so, call obj->ref() +/** Call obj->ref() and return obj. The obj must not be NULL. */ -template static inline void SkSafeRef(T* obj) { +template static inline T* SkRef(T* obj) { + SkASSERT(obj); + obj->ref(); + return obj; +} + +/** Check if the argument is non-null, and if so, call obj->ref() and return obj. + */ +template static inline T* SkSafeRef(T* obj) { if (obj) { obj->ref(); } + return obj; } /** Check if the argument is non-null, and if so, call obj->unref() -- 2.7.4