We currently rename |deref| -> |Deref|:
wtf/PassRefPtr.h:
template <typename T> ALWAYS_INLINE void DerefIfNotNull(T* ptr)
{
if (LIKELY(ptr != 0))
ptr->Deref();
}
wtf/RefCounted.h:
template<typename T> class RefCounted : public RefCountedBase {
...
public:
void Deref() const
{
if (DerefBase())
delete static_cast<const T*>(this);
}
The above looks good so far, but then we also use PassRefPtr<T> with non-WTF types:
void GraphicsContextState::SetDrawLooper(PassRefPtr<SkDrawLooper> draw_looper)
{
...
}
Which obviously didn't get the |deref| -> |Deref| renaming:
.../wtf/PassRefPtr.h:55:14: error: no member named 'Deref' in 'SkColorFilter'
ptr->Deref();
~~~ ^
.../wtf/PassRefPtr.h:72:35: note: in instantiation of function template specialization 'WTF::DerefIfNotNull<SkColorFilter>' requested here
ALWAYS_INLINE ~PassRefPtr() { DerefIfNotNull(ptr_); }
^
.../platform/graphics/GraphicsContextState.cpp:118:39: note: in instantiation of member function 'WTF::PassRefPtr<SkColorFilter>::~PassRefPtr' requested here
fill_paint_.setColorFilter(ToSkSp(color_filter));
Comment 1 by lukasza@chromium.org
, Aug 25 2016Maybe we can do something like this? template <typename T, typename std::enable_if<std::is_base_of<::WTF::RefCountedBase, T>::value>::type* = nullptr> ALWAYS_INLINE void DerefIfNotNull(T* ptr) { if (LIKELY(ptr != 0)) ptr->Deref(); } template <typename T, typename std::enable_if<!std::is_base_of<::WTF::RefCountedBase, T>::value>::type* = nullptr> ALWAYS_INLINE void DerefIfNotNull(T* ptr) { if (LIKELY(ptr != 0)) ptr->deref(); } This looks like a terrible, desperate hack, but it works (for Deref-vs-deref at least; I am still trying to figure out how to make it work for Ref-vs-ref).