Changeset 65130 in webkit for trunk/JavaScriptCore/wtf/RefPtr.h


Ignore:
Timestamp:
Aug 11, 2010, 12:08:23 AM (15 years ago)
Author:
[email protected]
Message:

2010-08-10 Darin Adler <Darin Adler>

Reviewed by Sam Weinig.

Add leakRef and clear to all RefPtr variants
https://bugs.webkit.org/show_bug.cgi?id=42389

  • API/JSRetainPtr.h: Changed all uses of "template <...>" to instead do "template<...>". We should probably put this in the style guide and do it consitently. Fixed other minor style issues. Defined many of the inlined functions outside the class definition, to avoid style checker warnings about multiple statements on a single line and for slightly better clarity of the class definition itself. Renamed releaseRef to leakRef. Added a releaseRef that calls leakRef so we don't have to rename all callers oat once. Added a clear function.
  • wtf/PassRefPtr.h: Changed all uses of releaseRef to leakRef.
  • wtf/RefPtr.h: Changed all uses of "template <...>" to instead do "template<...>". Tidied up declarations and comments a bit. Changed all uses of releaseRef to leakRef.
  • wtf/RetainPtr.h: Changed all uses of "template <...>" to instead do "template<...>". Defined many of the inlined functions outside the class definition, to avoid style checker warnings about multiple statements on a single line and for slightly better clarity of the class definition itself. Renamed releaseRef to leakRef. Added a releaseRef that calls leakRef so we don't have to rename all callers at once. Added a clear function.

2010-08-10 Darin Adler <Darin Adler>

Reviewed by Sam Weinig.

Add leakRef and clear to all RefPtr variants
https://bugs.webkit.org/show_bug.cgi?id=42389

  • platform/win/COMPtr.h: Changed all uses of "template <...>" to instead do "template<...>". Defined many of the inlined functions outside the class definition, to avoid style checker warnings about multiple statements on a single line and for slightly better clarity of the class definition itself. Renamed releaseRef to leakRef. Added a releaseRef that calls leakRef so we don't have to rename all callers at once. Added a clear function. Changed the hash table code so it doesn't need to call releaseRef, and so it uses the hash table deleted value hooks already present within the class.

2010-08-10 Darin Adler <Darin Adler>

Reviewed by Sam Weinig.

Add leakRef and clear to all RefPtr variants
https://bugs.webkit.org/show_bug.cgi?id=42389

  • UIProcess/API/cpp/WKRetainPtr.h: Changed all uses of "template <...>" to "template<...>". Defined many of the inlined functions outside the class definition, to avoid style checker warnings about multiple statements on a single line and for slightly better clarity of the class definition itself. Renamed releaseRef to leakRef. Added a releaseRef that calls leakRef so we don't have to rename all callers at once. Added a clear function.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/RefPtr.h

    r62674 r65130  
    3333    enum PlacementNewAdoptType { PlacementNewAdopt };
    3434
    35     template <typename T> class PassRefPtr;
    36     template <typename T> class NonNullPassRefPtr;
     35    template<typename T> class PassRefPtr;
     36    template<typename T> class NonNullPassRefPtr;
    3737
    3838    enum HashTableDeletedValueType { HashTableDeletedValue };
    3939
    40     template <typename T> class RefPtr : public FastAllocBase {
     40    template<typename T> class RefPtr : public FastAllocBase {
    4141    public:
    4242        ALWAYS_INLINE RefPtr() : m_ptr(0) { }
    4343        ALWAYS_INLINE RefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); }
    44         ALWAYS_INLINE RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { T* ptr = m_ptr; refIfNotNull(ptr); }
    45         // see comment in PassRefPtr.h for why this takes const reference
    46         template <typename U> RefPtr(const PassRefPtr<U>&);
    47         template <typename U> RefPtr(const NonNullPassRefPtr<U>&);
     44        ALWAYS_INLINE RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { refIfNotNull(m_ptr); }
     45        template<typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { refIfNotNull(m_ptr); }
     46
     47        // See comments in PassRefPtr.h for an explanation of why these takes const references.
     48        template<typename U> RefPtr(const PassRefPtr<U>&);
     49        template<typename U> RefPtr(const NonNullPassRefPtr<U>&);
    4850
    4951        // Special constructor for cases where we overwrite an object in place.
     
    5557
    5658        ALWAYS_INLINE ~RefPtr() { derefIfNotNull(m_ptr); }
    57        
    58         template <typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { T* ptr = m_ptr; refIfNotNull(ptr); }
    59        
     59
    6060        T* get() const { return m_ptr; }
    6161       
     
    7676        RefPtr& operator=(const PassRefPtr<T>&);
    7777        RefPtr& operator=(const NonNullPassRefPtr<T>&);
    78         template <typename U> RefPtr& operator=(const RefPtr<U>&);
    79         template <typename U> RefPtr& operator=(const PassRefPtr<U>&);
    80         template <typename U> RefPtr& operator=(const NonNullPassRefPtr<U>&);
     78        template<typename U> RefPtr& operator=(const RefPtr<U>&);
     79        template<typename U> RefPtr& operator=(const PassRefPtr<U>&);
     80        template<typename U> RefPtr& operator=(const NonNullPassRefPtr<U>&);
    8181
    8282        void swap(RefPtr&);
     
    8888    };
    8989   
    90     template <typename T> template <typename U> inline RefPtr<T>::RefPtr(const PassRefPtr<U>& o)
    91         : m_ptr(o.releaseRef())
    92     {
    93     }
    94 
    95     template <typename T> template <typename U> inline RefPtr<T>::RefPtr(const NonNullPassRefPtr<U>& o)
    96         : m_ptr(o.releaseRef())
    97     {
    98     }
    99 
    100     template <typename T> inline void RefPtr<T>::clear()
     90    template<typename T> template<typename U> inline RefPtr<T>::RefPtr(const PassRefPtr<U>& o)
     91        : m_ptr(o.leakRef())
     92    {
     93    }
     94
     95    template<typename T> template<typename U> inline RefPtr<T>::RefPtr(const NonNullPassRefPtr<U>& o)
     96        : m_ptr(o.leakRef())
     97    {
     98    }
     99
     100    template<typename T> inline void RefPtr<T>::clear()
    101101    {
    102102        T* ptr = m_ptr;
     
    105105    }
    106106
    107     template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<T>& o)
     107    template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<T>& o)
    108108    {
    109109        T* optr = o.get();
     
    115115    }
    116116   
    117     template <typename T> template <typename U> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<U>& o)
     117    template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<U>& o)
    118118    {
    119119        T* optr = o.get();
     
    125125    }
    126126   
    127     template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(T* optr)
     127    template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(T* optr)
    128128    {
    129129        refIfNotNull(optr);
     
    134134    }
    135135
    136     template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<T>& o)
    137     {
    138         T* ptr = m_ptr;
    139         m_ptr = o.releaseRef();
    140         derefIfNotNull(ptr);
    141         return *this;
    142     }
    143 
    144     template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(const NonNullPassRefPtr<T>& o)
    145     {
    146         T* ptr = m_ptr;
    147         m_ptr = o.releaseRef();
    148         derefIfNotNull(ptr);
    149         return *this;
    150     }
    151 
    152     template <typename T> template <typename U> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<U>& o)
    153     {
    154         T* ptr = m_ptr;
    155         m_ptr = o.releaseRef();
    156         derefIfNotNull(ptr);
    157         return *this;
    158     }
    159 
    160     template <typename T> template <typename U> inline RefPtr<T>& RefPtr<T>::operator=(const NonNullPassRefPtr<U>& o)
    161     {
    162         T* ptr = m_ptr;
    163         m_ptr = o.releaseRef();
    164         derefIfNotNull(ptr);
    165         return *this;
    166     }
    167 
    168     template <class T> inline void RefPtr<T>::swap(RefPtr<T>& o)
     136    template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<T>& o)
     137    {
     138        T* ptr = m_ptr;
     139        m_ptr = o.leakRef();
     140        derefIfNotNull(ptr);
     141        return *this;
     142    }
     143
     144    template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(const NonNullPassRefPtr<T>& o)
     145    {
     146        T* ptr = m_ptr;
     147        m_ptr = o.leakRef();
     148        derefIfNotNull(ptr);
     149        return *this;
     150    }
     151
     152    template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<U>& o)
     153    {
     154        T* ptr = m_ptr;
     155        m_ptr = o.leakRef();
     156        derefIfNotNull(ptr);
     157        return *this;
     158    }
     159
     160    template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const NonNullPassRefPtr<U>& o)
     161    {
     162        T* ptr = m_ptr;
     163        m_ptr = o.leakRef();
     164        derefIfNotNull(ptr);
     165        return *this;
     166    }
     167
     168    template<class T> inline void RefPtr<T>::swap(RefPtr<T>& o)
    169169    {
    170170        std::swap(m_ptr, o.m_ptr);
    171171    }
    172172
    173     template <class T> inline void swap(RefPtr<T>& a, RefPtr<T>& b)
     173    template<class T> inline void swap(RefPtr<T>& a, RefPtr<T>& b)
    174174    {
    175175        a.swap(b);
    176176    }
    177177
    178     template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, const RefPtr<U>& b)
     178    template<typename T, typename U> inline bool operator==(const RefPtr<T>& a, const RefPtr<U>& b)
    179179    {
    180180        return a.get() == b.get();
    181181    }
    182182
    183     template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, U* b)
     183    template<typename T, typename U> inline bool operator==(const RefPtr<T>& a, U* b)
    184184    {
    185185        return a.get() == b;
    186186    }
    187187   
    188     template <typename T, typename U> inline bool operator==(T* a, const RefPtr<U>& b)
     188    template<typename T, typename U> inline bool operator==(T* a, const RefPtr<U>& b)
    189189    {
    190190        return a == b.get();
    191191    }
    192192   
    193     template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const RefPtr<U>& b)
     193    template<typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const RefPtr<U>& b)
    194194    {
    195195        return a.get() != b.get();
    196196    }
    197197
    198     template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, U* b)
     198    template<typename T, typename U> inline bool operator!=(const RefPtr<T>& a, U* b)
    199199    {
    200200        return a.get() != b;
    201201    }
    202202
    203     template <typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>& b)
     203    template<typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>& b)
    204204    {
    205205        return a != b.get();
    206206    }
    207207   
    208     template <typename T, typename U> inline RefPtr<T> static_pointer_cast(const RefPtr<U>& p)
     208    template<typename T, typename U> inline RefPtr<T> static_pointer_cast(const RefPtr<U>& p)
    209209    {
    210210        return RefPtr<T>(static_cast<T*>(p.get()));
    211211    }
    212212
    213     template <typename T, typename U> inline RefPtr<T> const_pointer_cast(const RefPtr<U>& p)
     213    template<typename T, typename U> inline RefPtr<T> const_pointer_cast(const RefPtr<U>& p)
    214214    {
    215215        return RefPtr<T>(const_cast<T*>(p.get()));
    216216    }
    217217
    218     template <typename T> inline T* getPtr(const RefPtr<T>& p)
     218    template<typename T> inline T* getPtr(const RefPtr<T>& p)
    219219    {
    220220        return p.get();
Note: See TracChangeset for help on using the changeset viewer.