Remove RefPtrHashMap

The recently added 'HashTraits::PeekInType' type allows us to remove
HashMap<RefPtr..> template specialization without loosing the efficiency
and without bringing any significant changes and complexity to the HashMap
class.

To get rid of 'RefPtrHashMap' a new 'RefPtrValuePeeker' type was created
and used as 'HashTraits::PeekInType' for RefPtr. The 'RefPtrValuePeeker'
class can be constructed either from RefPtr, PassRefPtr or a plain pointer,
then it behaves like a plain pointer itself within HashTable methods.

The proposed change brings the following benefits:
1) Removes tons of duplicated code
2) Allows avoiding ref-count churn also at HashSet<RefPtr>

Review URL: https://codereview.chromium.org/184233006

git-svn-id: svn://svn.chromium.org/blink/trunk@168593 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ac9b8162
...@@ -526,6 +526,4 @@ namespace WTF { ...@@ -526,6 +526,4 @@ namespace WTF {
using WTF::HashMap; using WTF::HashMap;
#include "wtf/RefPtrHashMap.h"
#endif /* WTF_HashMap_h */ #endif /* WTF_HashMap_h */
...@@ -170,7 +170,7 @@ namespace WTF { ...@@ -170,7 +170,7 @@ namespace WTF {
static const bool hasIsEmptyValueFunction = true; static const bool hasIsEmptyValueFunction = true;
static bool isEmptyValue(const RefPtr<P>& value) { return !value; } static bool isEmptyValue(const RefPtr<P>& value) { return !value; }
typedef const RefPtr<P>& PeekInType; typedef RefPtrValuePeeker<P> PeekInType;
typedef RefPtr<P>* IteratorGetType; typedef RefPtr<P>* IteratorGetType;
typedef const RefPtr<P>* IteratorConstGetType; typedef const RefPtr<P>* IteratorConstGetType;
typedef RefPtr<P>& IteratorReferenceType; typedef RefPtr<P>& IteratorReferenceType;
......
...@@ -188,6 +188,16 @@ namespace WTF { ...@@ -188,6 +188,16 @@ namespace WTF {
return p.get(); return p.get();
} }
template<typename T> class RefPtrValuePeeker {
public:
ALWAYS_INLINE RefPtrValuePeeker(T* p): m_ptr(p) { }
template<typename U> RefPtrValuePeeker(const RefPtr<U>& p): m_ptr(p.get()) { }
template<typename U> RefPtrValuePeeker(const PassRefPtr<U>& p): m_ptr(p.get()) { }
ALWAYS_INLINE operator T*() const { return m_ptr; }
private:
T* m_ptr;
};
} // namespace WTF } // namespace WTF
using WTF::RefPtr; using WTF::RefPtr;
......
This diff is collapsed.
...@@ -99,7 +99,6 @@ ...@@ -99,7 +99,6 @@
'RefCountedLeakCounter.cpp', 'RefCountedLeakCounter.cpp',
'RefCountedLeakCounter.h', 'RefCountedLeakCounter.h',
'RefPtr.h', 'RefPtr.h',
'RefPtrHashMap.h',
'RetainPtr.h', 'RetainPtr.h',
'SHA1.cpp', 'SHA1.cpp',
'SHA1.h', 'SHA1.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment