Commit 57947f0d authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

Switch AdoptRef to use RefPtr<T>.

Bug: 494719
Change-Id: I8c6f86d1ccee6c3aed22d8ff432f089d6b66db76
Reviewed-on: https://chromium-review.googlesource.com/538918
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#480298}
parent 1b6c0c88
......@@ -6,7 +6,7 @@
namespace blink {
PassRefPtr<HTMLParserReentryPermit> HTMLParserReentryPermit::Create() {
RefPtr<HTMLParserReentryPermit> HTMLParserReentryPermit::Create() {
return AdoptRef(new HTMLParserReentryPermit());
}
......
......@@ -6,8 +6,8 @@
#define HTMLParserReentryPermit_h
#include "base/macros.h"
#include "platform/wtf/PassRefPtr.h"
#include "platform/wtf/RefCounted.h"
#include "platform/wtf/RefPtr.h"
namespace blink {
......@@ -38,7 +38,7 @@ namespace blink {
class HTMLParserReentryPermit final
: public RefCounted<HTMLParserReentryPermit> {
public:
static PassRefPtr<HTMLParserReentryPermit> Create();
static RefPtr<HTMLParserReentryPermit> Create();
~HTMLParserReentryPermit() = default;
unsigned ScriptNestingLevel() const { return script_nesting_level_; }
......
......@@ -22,14 +22,14 @@
#define CustomFontData_h
#include "platform/PlatformExport.h"
#include "platform/wtf/PassRefPtr.h"
#include "platform/wtf/RefCounted.h"
#include "platform/wtf/RefPtr.h"
namespace blink {
class PLATFORM_EXPORT CustomFontData : public RefCounted<CustomFontData> {
public:
static PassRefPtr<CustomFontData> Create() {
static RefPtr<CustomFontData> Create() {
return AdoptRef(new CustomFontData());
}
......
......@@ -37,10 +37,6 @@ template <typename T>
class RefPtr;
template <typename T>
class PassRefPtr;
template <typename T>
PassRefPtr<T> AdoptRef(T*);
inline void Adopted(const void*) {}
// requireAdoption() is not overloaded for WTF::RefCounted, which has a built-in
// assumption that adoption is required. requireAdoption() is for bootstrapping
......@@ -94,12 +90,7 @@ class PassRefPtr {
bool operator!() const { return !ptr_; }
explicit operator bool() const { return ptr_ != nullptr; }
friend PassRefPtr AdoptRef<T>(T*);
private:
enum AdoptRefTag { kAdoptRef };
PassRefPtr(T* ptr, AdoptRefTag) : ptr_(ptr) {}
PassRefPtr& operator=(const PassRefPtr&) {
static_assert(!sizeof(T*), "PassRefPtr should never be assigned to");
return *this;
......@@ -205,12 +196,6 @@ inline bool operator!=(std::nullptr_t, const PassRefPtr<T>& b) {
return b.Get();
}
template <typename T>
PassRefPtr<T> AdoptRef(T* p) {
Adopted(p);
return PassRefPtr<T>(p, PassRefPtr<T>::kAdoptRef);
}
template <typename T>
inline T* GetPtr(const PassRefPtr<T>& p) {
return p.Get();
......@@ -219,6 +204,5 @@ inline T* GetPtr(const PassRefPtr<T>& p) {
} // namespace WTF
using WTF::PassRefPtr;
using WTF::AdoptRef;
#endif // WTF_PassRefPtr_h
......@@ -5,6 +5,7 @@
#include "platform/wtf/PassRefPtr.h"
#include "platform/wtf/RefCounted.h"
#include "platform/wtf/RefPtr.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace WTF {
......
......@@ -35,6 +35,13 @@ template <typename T>
class PassRefPtr;
template <typename T>
class RefPtrValuePeeker;
template <typename T>
class RefPtr;
template <typename T>
RefPtr<T> AdoptRef(T*);
inline void Adopted(const void*) {}
template <typename T>
class RefPtr {
......@@ -52,6 +59,9 @@ class RefPtr {
RefIfNotNull(ptr_);
}
RefPtr(RefPtr&& o) : ptr_(o.ptr_) { o.ptr_ = nullptr; }
template <typename U>
RefPtr(RefPtr<U>&& o, EnsurePtrConvertibleArgDecl(U, T))
: ptr_(o.LeakRef()) {}
// See comments in PassRefPtr.h for an explanation of why this takes a const
// reference.
......@@ -70,11 +80,7 @@ class RefPtr {
ALWAYS_INLINE T* Get() const { return ptr_; }
T* LeakRef() WARN_UNUSED_RESULT;
void Clear();
PassRefPtr<T> Release() WARN_UNUSED_RESULT {
PassRefPtr<T> tmp = AdoptRef(ptr_);
ptr_ = nullptr;
return tmp;
}
PassRefPtr<T> Release() WARN_UNUSED_RESULT { return std::move(*this); }
T& operator*() const { return *ptr_; }
ALWAYS_INLINE T* operator->() const { return ptr_; }
......@@ -99,6 +105,11 @@ class RefPtr {
static T* HashTableDeletedValue() { return reinterpret_cast<T*>(-1); }
private:
friend RefPtr AdoptRef<T>(T*);
enum AdoptRefTag { kAdoptRef };
RefPtr(T* ptr, AdoptRefTag) : ptr_(ptr) {}
T* ptr_;
};
......@@ -212,8 +223,15 @@ class RefPtrValuePeeker {
T* ptr_;
};
template <typename T>
RefPtr<T> AdoptRef(T* p) {
Adopted(p);
return RefPtr<T>(p, RefPtr<T>::kAdoptRef);
}
} // namespace WTF
using WTF::RefPtr;
using WTF::AdoptRef;
#endif // WTF_RefPtr_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