diff options
author | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-23 19:21:18 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-23 19:21:18 +0000 |
commit | 405c556a510d9ee1b827a70a5f2294cac42a278c (patch) | |
tree | e9a28886c8979beda858faae66edb42bf1e7a124 /base | |
parent | 408f2188cdce0e0d82571be4d9dfa7227751fb1b (diff) | |
download | chromium_src-405c556a510d9ee1b827a70a5f2294cac42a278c.zip chromium_src-405c556a510d9ee1b827a70a5f2294cac42a278c.tar.gz chromium_src-405c556a510d9ee1b827a70a5f2294cac42a278c.tar.bz2 |
Improve scoped_cftyperef<> and scoped_nsobject<> reset() semantics.
Review URL: http://codereview.chromium.org/52018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12301 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/scoped_cftyperef.h | 12 | ||||
-rw-r--r-- | base/scoped_nsobject.h | 10 |
2 files changed, 11 insertions, 11 deletions
diff --git a/base/scoped_cftyperef.h b/base/scoped_cftyperef.h index d32aa51..7b4f1e6 100644 --- a/base/scoped_cftyperef.h +++ b/base/scoped_cftyperef.h @@ -15,7 +15,9 @@ // // When scoped_cftyperef<> takes ownership of an object (in the constructor or // in reset()), it takes over the caller's existing ownership claim. The -// caller must own the object. scoped_cftyperef<> does not call CFRetain(). +// caller must own the object it gives to scoped_cftyperef<>, and relinquishes +// an ownership claim to that object. scoped_cftyperef<> does not call +// CFRetain(). template<typename CFT> class scoped_cftyperef { public: @@ -31,11 +33,9 @@ class scoped_cftyperef { } void reset(CFT object = NULL) { - if (object_ != object) { - if (object_) - CFRelease(object_); - object_ = object; - } + if (object_) + CFRelease(object_); + object_ = object; } bool operator==(CFT that) const { diff --git a/base/scoped_nsobject.h b/base/scoped_nsobject.h index 12e3a37..2c808c6 100644 --- a/base/scoped_nsobject.h +++ b/base/scoped_nsobject.h @@ -15,7 +15,9 @@ // // When scoped_nsobject<> takes ownership of an object (in the constructor or // in reset()), it takes over the caller's existing ownership claim. The -// caller must own the object. scoped_nsobject<> does not call -retain. +// caller must own the object it gives to scoped_nsobject<>, and relinquishes +// an ownership claim to that object. scoped_nsobject<> does not call +// -retain. template<typename NST> class scoped_nsobject { public: @@ -30,10 +32,8 @@ class scoped_nsobject { } void reset(NST* object = nil) { - if (object_ != object) { - [object_ release]; - object_ = object; - } + [object_ release]; + object_ = object; } bool operator==(NST* that) const { |