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/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.