Changeset 65130 in webkit for trunk/JavaScriptCore/wtf


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.
Location:
trunk/JavaScriptCore/wtf
Files:
3 edited

Legend:

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

    r63562 r65130  
    6868        // a const PassRefPtr. However, it makes it much easier to work with PassRefPtr
    6969        // temporaries, and we don't have a need to use real const PassRefPtrs anyway.
    70         PassRefPtr(const PassRefPtr& o) : m_ptr(o.releaseRef()) { }
    71         template<typename U> PassRefPtr(const PassRefPtr<U>& o) : m_ptr(o.releaseRef()) { }
     70        PassRefPtr(const PassRefPtr& o) : m_ptr(o.leakRef()) { }
     71        template<typename U> PassRefPtr(const PassRefPtr<U>& o) : m_ptr(o.leakRef()) { }
    7272
    7373        ALWAYS_INLINE ~PassRefPtr() { derefIfNotNull(m_ptr); }
     
    107107   
    108108    // NonNullPassRefPtr: Optimized for passing non-null pointers. A NonNullPassRefPtr
    109     // begins life non-null, and can only become null through a call to releaseRef()
     109    // begins life non-null, and can only become null through a call to leakRef()
    110110    // or clear().
    111111
     
    131131
    132132        NonNullPassRefPtr(const NonNullPassRefPtr& o)
    133             : m_ptr(o.releaseRef())
     133            : m_ptr(o.leakRef())
    134134        {
    135135            ASSERT(m_ptr);
     
    137137
    138138        template<typename U> NonNullPassRefPtr(const NonNullPassRefPtr<U>& o)
    139             : m_ptr(o.releaseRef())
     139            : m_ptr(o.leakRef())
    140140        {
    141141            ASSERT(m_ptr);
     
    143143
    144144        template<typename U> NonNullPassRefPtr(const PassRefPtr<U>& o)
    145             : m_ptr(o.releaseRef())
     145            : m_ptr(o.leakRef())
    146146        {
    147147            ASSERT(m_ptr);
     
    208208    {
    209209        T* ptr = m_ptr;
    210         m_ptr = ref.releaseRef();
     210        m_ptr = ref.leakRef();
    211211        derefIfNotNull(ptr);
    212212        return *this;
     
    216216    {
    217217        T* ptr = m_ptr;
    218         m_ptr = ref.releaseRef();
     218        m_ptr = ref.leakRef();
    219219        derefIfNotNull(ptr);
    220220        return *this;
     
    279279    template<typename T, typename U> inline PassRefPtr<T> static_pointer_cast(const PassRefPtr<U>& p)
    280280    {
    281         return adoptRef(static_cast<T*>(p.releaseRef()));
     281        return adoptRef(static_cast<T*>(p.leakRef()));
    282282    }
    283283
    284284    template<typename T, typename U> inline PassRefPtr<T> const_pointer_cast(const PassRefPtr<U>& p)
    285285    {
    286         return adoptRef(const_cast<T*>(p.releaseRef()));
     286        return adoptRef(const_cast<T*>(p.leakRef()));
    287287    }
    288288
  • 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();
  • trunk/JavaScriptCore/wtf/RetainPtr.h

    r63562 r65130  
    11/*
    2  *  Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
     2 *  Copyright (C) 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
    33 *
    44 *  This library is free software; you can redistribute it and/or
     
    4949#endif
    5050
    51     template <typename T> class RetainPtr {
     51    template<typename T> class RetainPtr {
    5252    public:
    5353        typedef typename RemovePointer<T>::Type ValueType;
     
    6868        ~RetainPtr() { if (PtrType ptr = m_ptr) CFRelease(ptr); }
    6969       
    70         template <typename U> RetainPtr(const RetainPtr<U>& o) : m_ptr(o.get()) { if (PtrType ptr = m_ptr) CFRetain(ptr); }
     70        template<typename U> RetainPtr(const RetainPtr<U>&);
    7171       
    7272        PtrType get() const { return m_ptr; }
    73        
    74         PtrType releaseRef() { PtrType tmp = m_ptr; m_ptr = 0; return tmp; }
    75        
     73
     74        void clear();
     75        PtrType leakRef() WARN_UNUSED_RETURN;
     76
    7677        PtrType operator->() const { return m_ptr; }
    7778       
     
    8384       
    8485        RetainPtr& operator=(const RetainPtr&);
    85         template <typename U> RetainPtr& operator=(const RetainPtr<U>&);
     86        template<typename U> RetainPtr& operator=(const RetainPtr<U>&);
    8687        RetainPtr& operator=(PtrType);
    87         template <typename U> RetainPtr& operator=(U*);
     88        template<typename U> RetainPtr& operator=(U*);
    8889
    8990        void adoptCF(PtrType);
     
    9293        void swap(RetainPtr&);
    9394
     95        // FIXME: Remove releaseRef once we change all callers to call leakRef instead.
     96        PtrType releaseRef() { return leakRef(); }
     97
    9498    private:
    9599        static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); }
     
    98102    };
    99103   
    100     template <typename T> inline RetainPtr<T>& RetainPtr<T>::operator=(const RetainPtr<T>& o)
     104    template<typename T> template<typename U> inline RetainPtr<T>::RetainPtr(const RetainPtr<U>& o)
     105        : m_ptr(o.get())
     106    {
     107        if (PtrType ptr = m_ptr)
     108            CFRetain(ptr);
     109    }
     110
     111    template<typename T> inline void RetainPtr<T>::clear()
     112    {
     113        if (PtrType ptr = m_ptr) {
     114            m_ptr = 0;
     115            CFRelease(ptr);
     116        }
     117    }
     118
     119    template<typename T> inline typename RetainPtr<T>::PtrType RetainPtr<T>::leakRef()
     120    {
     121        PtrType ptr = m_ptr;
     122        m_ptr = 0;
     123        return ptr;
     124    }
     125
     126    template<typename T> inline RetainPtr<T>& RetainPtr<T>::operator=(const RetainPtr<T>& o)
    101127    {
    102128        PtrType optr = o.get();
     
    110136    }
    111137   
    112     template <typename T> template <typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(const RetainPtr<U>& o)
     138    template<typename T> template<typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(const RetainPtr<U>& o)
    113139    {
    114140        PtrType optr = o.get();
     
    122148    }
    123149   
    124     template <typename T> inline RetainPtr<T>& RetainPtr<T>::operator=(PtrType optr)
    125     {
    126         if (optr)
    127             CFRetain(optr);
    128         PtrType ptr = m_ptr;
    129         m_ptr = optr;
    130         if (ptr)
    131             CFRelease(ptr);
    132         return *this;
    133     }
    134 
    135     template <typename T> inline void RetainPtr<T>::adoptCF(PtrType optr)
    136     {
    137         PtrType ptr = m_ptr;
    138         m_ptr = optr;
    139         if (ptr)
    140             CFRelease(ptr);
    141     }
    142 
    143     template <typename T> inline void RetainPtr<T>::adoptNS(PtrType optr)
     150    template<typename T> inline RetainPtr<T>& RetainPtr<T>::operator=(PtrType optr)
     151    {
     152        if (optr)
     153            CFRetain(optr);
     154        PtrType ptr = m_ptr;
     155        m_ptr = optr;
     156        if (ptr)
     157            CFRelease(ptr);
     158        return *this;
     159    }
     160
     161    template<typename T> inline void RetainPtr<T>::adoptCF(PtrType optr)
     162    {
     163        PtrType ptr = m_ptr;
     164        m_ptr = optr;
     165        if (ptr)
     166            CFRelease(ptr);
     167    }
     168
     169    template<typename T> inline void RetainPtr<T>::adoptNS(PtrType optr)
    144170    {
    145171        adoptNSReference(optr);
     
    151177    }
    152178   
    153     template <typename T> template <typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(U* optr)
    154     {
    155         if (optr)
    156             CFRetain(optr);
    157         PtrType ptr = m_ptr;
    158         m_ptr = optr;
    159         if (ptr)
    160             CFRelease(ptr);
    161         return *this;
    162     }
    163 
    164     template <class T> inline void RetainPtr<T>::swap(RetainPtr<T>& o)
     179    template<typename T> template<typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(U* optr)
     180    {
     181        if (optr)
     182            CFRetain(optr);
     183        PtrType ptr = m_ptr;
     184        m_ptr = optr;
     185        if (ptr)
     186            CFRelease(ptr);
     187        return *this;
     188    }
     189
     190    template<typename T> inline void RetainPtr<T>::swap(RetainPtr<T>& o)
    165191    {
    166192        std::swap(m_ptr, o.m_ptr);
    167193    }
    168194
    169     template <class T> inline void swap(RetainPtr<T>& a, RetainPtr<T>& b)
     195    template<typename T> inline void swap(RetainPtr<T>& a, RetainPtr<T>& b)
    170196    {
    171197        a.swap(b);
    172198    }
    173199
    174     template <typename T, typename U> inline bool operator==(const RetainPtr<T>& a, const RetainPtr<U>& b)
     200    template<typename T, typename U> inline bool operator==(const RetainPtr<T>& a, const RetainPtr<U>& b)
    175201    {
    176202        return a.get() == b.get();
    177203    }
    178204
    179     template <typename T, typename U> inline bool operator==(const RetainPtr<T>& a, U* b)
     205    template<typename T, typename U> inline bool operator==(const RetainPtr<T>& a, U* b)
    180206    {
    181207        return a.get() == b;
    182208    }
    183209   
    184     template <typename T, typename U> inline bool operator==(T* a, const RetainPtr<U>& b)
     210    template<typename T, typename U> inline bool operator==(T* a, const RetainPtr<U>& b)
    185211    {
    186212        return a == b.get();
    187213    }
    188214   
    189     template <typename T, typename U> inline bool operator!=(const RetainPtr<T>& a, const RetainPtr<U>& b)
     215    template<typename T, typename U> inline bool operator!=(const RetainPtr<T>& a, const RetainPtr<U>& b)
    190216    {
    191217        return a.get() != b.get();
    192218    }
    193219
    194     template <typename T, typename U> inline bool operator!=(const RetainPtr<T>& a, U* b)
     220    template<typename T, typename U> inline bool operator!=(const RetainPtr<T>& a, U* b)
    195221    {
    196222        return a.get() != b;
    197223    }
    198224
    199     template <typename T, typename U> inline bool operator!=(T* a, const RetainPtr<U>& b)
     225    template<typename T, typename U> inline bool operator!=(T* a, const RetainPtr<U>& b)
    200226    {
    201227        return a != b.get();
Note: See TracChangeset for help on using the changeset viewer.