Commit eab8e967 authored by tzik's avatar tzik Committed by Commit Bot

Reduce wtf/RefPtr.h

This CL contains:
 - Moves WTF::GetPtr overload for RefPtr to wtf/GetPtr.h,
 - Moves RefPtrValuePeeker to wtf/HashFunctions.h
 - Merges WTF::AdoptRef and base::AdoptRef.
as a preparation of RefPtr.h removal.

Bug: 763844
Change-Id: Iac2cfe6af0304ed4ea180f6ed50a08e9065672b9
Reviewed-on: https://chromium-review.googlesource.com/727683Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510145}
parent 29da39eb
......@@ -21,6 +21,9 @@
#ifndef WTF_GetPtr_h
#define WTF_GetPtr_h
template <typename>
class scoped_refptr;
namespace WTF {
template <typename T>
......@@ -33,6 +36,11 @@ inline T* GetPtr(T& p) {
return &p;
}
template <typename T>
inline T* GetPtr(const scoped_refptr<T>& p) {
return p.get();
}
} // namespace WTF
#endif // WTF_GetPtr_h
......@@ -27,6 +27,7 @@
#include <memory>
#include <type_traits>
#include <utility>
#include "platform/wtf/Allocator.h"
#include "platform/wtf/Forward.h"
#include "platform/wtf/HashFunctions.h"
#include "platform/wtf/HashTableDeletedValueType.h"
......@@ -219,6 +220,20 @@ struct HashTraits<RefPtr<P>> : SimpleClassHashTraits<RefPtr<P>> {
"Unexpected RefPtr size."
" RefPtr needs to be single pointer to support deleted value.");
class RefPtrValuePeeker {
DISALLOW_NEW();
public:
ALWAYS_INLINE RefPtrValuePeeker(P* p) : ptr_(p) {}
template <typename U>
RefPtrValuePeeker(const RefPtr<U>& p) : ptr_(p.get()) {}
ALWAYS_INLINE operator P*() const { return ptr_; }
private:
P* ptr_;
};
typedef std::nullptr_t EmptyValueType;
static EmptyValueType EmptyValue() { return nullptr; }
......@@ -234,7 +249,7 @@ struct HashTraits<RefPtr<P>> : SimpleClassHashTraits<RefPtr<P>> {
*reinterpret_cast<void**>(&slot) = reinterpret_cast<void*>(-1);
}
typedef RefPtrValuePeeker<P> PeekInType;
typedef RefPtrValuePeeker PeekInType;
typedef RefPtr<P>* IteratorGetType;
typedef const RefPtr<P>* IteratorConstGetType;
typedef RefPtr<P>& IteratorReferenceType;
......
......@@ -23,37 +23,13 @@
#define WTF_RefPtr_h
#include "base/memory/scoped_refptr.h"
#include "platform/wtf/Allocator.h"
namespace WTF {
template <typename T>
using RefPtr = scoped_refptr<T>;
template <typename T>
inline T* GetPtr(const RefPtr<T>& p) {
return p.get();
}
template <typename T>
class RefPtrValuePeeker {
DISALLOW_NEW();
public:
ALWAYS_INLINE RefPtrValuePeeker(T* p) : ptr_(p) {}
template <typename U>
RefPtrValuePeeker(const RefPtr<U>& p) : ptr_(p.get()) {}
ALWAYS_INLINE operator T*() const { return ptr_; }
private:
T* ptr_;
};
template <typename T>
RefPtr<T> AdoptRef(T* p) {
return RefPtr<T>(base::AdoptRef(p));
}
using base::AdoptRef;
template <typename T>
RefPtr<T> WrapRefPtr(T* ptr) {
......
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