Skip to content
This repository
Browse code

Took jmarshall suggestion and modified the Referenced::ref<T> smart p…

…ointer's operator= so that it didn't need to temporary variable. This allowed me to eliminate some of the comment that was there to explain the temporary.
  • Loading branch information...
commit fed9272caaa15171d90d309db55c228bde12a5cf 1 parent 9254ca6
Jim Carroll authored

Showing 1 changed file with 2 additions and 12 deletions. Show diff stats Hide diff stats

  1. +2 12 xbmc/utils/ReferenceCounting.h
14 xbmc/utils/ReferenceCounting.h
@@ -75,21 +75,11 @@ namespace xbmcutil
75 75 * operator= should work with either another smart pointer or a pointer since it will
76 76 * be able to convert a pointer to a smart pointer using one of the above constuctors.
77 77 *
78   - * Note: There is a trick here. The temporary varialbe is necessary because otherwise the
79   - * following code will fail:
80   - *
81   - * ref<T> ptr = new T;
82   - * ptr = ptr;
83   - *
84   - * What happens without the tmp is the derefernce is called first so the object ends up
85   - * deleted and then the reference happens on a deleted object. The order is reversed
86   - * in the following.
87   - *
88 78 * Note: Operator= is ambiguous if you define both an operator=(ref<T>&) and an operator=(T*). I'm
89   - * opting for the route the boost took here figuring it has more history behind it.
  79 + * opting for the route that boost took here figuring it has more history behind it.
90 80 */
91 81 inline ref<T>& operator=(ref<T> const & oref)
92   - { T* tmp = ac; ac=((T*)oref.get()); if (ac) ac->Acquire(); if (tmp) tmp->Release(); refcheck; return *this; }
  82 + { if (this != &oref) { if (ac) ac->Release(); ac=((T*)oref.get()); if (ac) ac->Acquire(); } refcheck; return *this; }
93 83
94 84 inline T* operator->() const { refcheck; return ac; }
95 85

0 comments on commit fed9272

Please sign in to comment.
Something went wrong with that request. Please try again.