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/API/JSRetainPtr.h

    r29663 r65130  
    11/*
    2  * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved.
     2 * Copyright (C) 2005, 2006, 2007, 2010 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3838enum AdoptTag { Adopt };
    3939
    40 template <typename T> class JSRetainPtr {
     40template<typename T> class JSRetainPtr {
    4141public:
    42     JSRetainPtr() : m_ptr(0) {}
     42    JSRetainPtr() : m_ptr(0) { }
    4343    JSRetainPtr(T ptr) : m_ptr(ptr) { if (ptr) JSRetain(ptr); }
    44 
    4544    JSRetainPtr(AdoptTag, T ptr) : m_ptr(ptr) { }
    46    
    47     JSRetainPtr(const JSRetainPtr& o) : m_ptr(o.m_ptr) { if (T ptr = m_ptr) JSRetain(ptr); }
    48 
    49     ~JSRetainPtr() { if (T ptr = m_ptr) JSRelease(ptr); }
    50    
    51     template <typename U> JSRetainPtr(const JSRetainPtr<U>& o) : m_ptr(o.get()) { if (T ptr = m_ptr) JSRetain(ptr); }
     45    JSRetainPtr(const JSRetainPtr&);
     46    template<typename U> JSRetainPtr(const JSRetainPtr<U>&);
     47    ~JSRetainPtr();
    5248   
    5349    T get() const { return m_ptr; }
    5450   
    55     T releaseRef() { T tmp = m_ptr; m_ptr = 0; return tmp; }
    56    
     51    void clear();
     52    T leakRef();
     53
    5754    T operator->() const { return m_ptr; }
    5855   
     
    6461   
    6562    JSRetainPtr& operator=(const JSRetainPtr&);
    66     template <typename U> JSRetainPtr& operator=(const JSRetainPtr<U>&);
     63    template<typename U> JSRetainPtr& operator=(const JSRetainPtr<U>&);
    6764    JSRetainPtr& operator=(T);
    68     template <typename U> JSRetainPtr& operator=(U*);
     65    template<typename U> JSRetainPtr& operator=(U*);
    6966
    7067    void adopt(T);
    7168   
    7269    void swap(JSRetainPtr&);
     70
     71    // FIXME: Remove releaseRef once we change all callers to call leakRef instead.
     72    T releaseRef() { return leakRef(); }
    7373
    7474private:
     
    7676};
    7777
    78 template <typename T> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(const JSRetainPtr<T>& o)
     78template<typename T> inline JSRetainPtr<T>::JSRetainPtr(const JSRetainPtr& o)
     79    : m_ptr(o.m_ptr)
     80{
     81    if (m_ptr)
     82        JSRetain(m_ptr);
     83}
     84
     85template<typename T> template<typename U> inline JSRetainPtr<T>::JSRetainPtr(const JSRetainPtr<U>& o)
     86    : m_ptr(o.get())
     87{
     88    if (m_ptr)
     89        JSRetain(m_ptr);
     90}
     91
     92template<typename T> inline JSRetainPtr<T>::~JSRetainPtr()
     93{
     94    if (m_ptr)
     95        JSRelease(m_ptr);
     96}
     97
     98template<typename T> inline void JSRetainPtr<T>::clear()
     99{
     100    if (T ptr = m_ptr) {
     101        m_ptr = 0;
     102        JSRelease(ptr);
     103    }
     104}
     105
     106template<typename T> inline T JSRetainPtr<T>::leakRef()
     107{
     108    T ptr = m_ptr;
     109    m_ptr = 0;
     110    return ptr;
     111}
     112
     113template<typename T> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(const JSRetainPtr<T>& o)
    79114{
    80115    T optr = o.get();
     
    88123}
    89124
    90 template <typename T> template <typename U> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(const JSRetainPtr<U>& o)
     125template<typename T> template<typename U> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(const JSRetainPtr<U>& o)
    91126{
    92127    T optr = o.get();
     
    100135}
    101136
    102 template <typename T> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(T optr)
    103 {
    104     if (optr)
    105         JSRetain(optr);
    106     T ptr = m_ptr;
    107     m_ptr = optr;
    108     if (ptr)
    109         JSRelease(ptr);
    110     return *this;
    111 }
    112 
    113 template <typename T> inline void JSRetainPtr<T>::adopt(T optr)
    114 {
    115     T ptr = m_ptr;
    116     m_ptr = optr;
    117     if (ptr)
    118         JSRelease(ptr);
    119 }
    120 
    121 template <typename T> template <typename U> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(U* optr)
    122 {
    123     if (optr)
    124         JSRetain(optr);
    125     T ptr = m_ptr;
    126     m_ptr = optr;
    127     if (ptr)
    128         JSRelease(ptr);
    129     return *this;
    130 }
    131 
    132 template <class T> inline void JSRetainPtr<T>::swap(JSRetainPtr<T>& o)
     137template<typename T> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(T optr)
     138{
     139    if (optr)
     140        JSRetain(optr);
     141    T ptr = m_ptr;
     142    m_ptr = optr;
     143    if (ptr)
     144        JSRelease(ptr);
     145    return *this;
     146}
     147
     148template<typename T> inline void JSRetainPtr<T>::adopt(T optr)
     149{
     150    T ptr = m_ptr;
     151    m_ptr = optr;
     152    if (ptr)
     153        JSRelease(ptr);
     154}
     155
     156template<typename T> template<typename U> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(U* optr)
     157{
     158    if (optr)
     159        JSRetain(optr);
     160    T ptr = m_ptr;
     161    m_ptr = optr;
     162    if (ptr)
     163        JSRelease(ptr);
     164    return *this;
     165}
     166
     167template<typename T> inline void JSRetainPtr<T>::swap(JSRetainPtr<T>& o)
    133168{
    134169    std::swap(m_ptr, o.m_ptr);
    135170}
    136171
    137 template <class T> inline void swap(JSRetainPtr<T>& a, JSRetainPtr<T>& b)
     172template<typename T> inline void swap(JSRetainPtr<T>& a, JSRetainPtr<T>& b)
    138173{
    139174    a.swap(b);
    140175}
    141176
    142 template <typename T, typename U> inline bool operator==(const JSRetainPtr<T>& a, const JSRetainPtr<U>& b)
     177template<typename T, typename U> inline bool operator==(const JSRetainPtr<T>& a, const JSRetainPtr<U>& b)
    143178{
    144179    return a.get() == b.get();
    145180}
    146181
    147 template <typename T, typename U> inline bool operator==(const JSRetainPtr<T>& a, U* b)
     182template<typename T, typename U> inline bool operator==(const JSRetainPtr<T>& a, U* b)
    148183{
    149184    return a.get() == b;
    150185}
    151186
    152 template <typename T, typename U> inline bool operator==(T* a, const JSRetainPtr<U>& b)
     187template<typename T, typename U> inline bool operator==(T* a, const JSRetainPtr<U>& b)
    153188{
    154189    return a == b.get();
    155190}
    156191
    157 template <typename T, typename U> inline bool operator!=(const JSRetainPtr<T>& a, const JSRetainPtr<U>& b)
     192template<typename T, typename U> inline bool operator!=(const JSRetainPtr<T>& a, const JSRetainPtr<U>& b)
    158193{
    159194    return a.get() != b.get();
    160195}
    161196
    162 template <typename T, typename U> inline bool operator!=(const JSRetainPtr<T>& a, U* b)
     197template<typename T, typename U> inline bool operator!=(const JSRetainPtr<T>& a, U* b)
    163198{
    164199    return a.get() != b;
    165200}
    166201
    167 template <typename T, typename U> inline bool operator!=(T* a, const JSRetainPtr<U>& b)
     202template<typename T, typename U> inline bool operator!=(T* a, const JSRetainPtr<U>& b)
    168203{
    169204    return a != b.get();
Note: See TracChangeset for help on using the changeset viewer.