mirror of
https://github.com/RGBCube/serenity
synced 2025-07-31 16:57:34 +00:00
AK: Rename RetainPtr => RefPtr and Retained => NonnullRefPtr.
This commit is contained in:
parent
77b9fa89dd
commit
90b1354688
188 changed files with 562 additions and 562 deletions
|
@ -12,7 +12,7 @@ namespace AK {
|
|||
|
||||
// String is a convenience wrapper around StringImpl, suitable for passing
|
||||
// around as a value type. It's basically the same as passing around a
|
||||
// RetainPtr<StringImpl>, with a bit of syntactic sugar.
|
||||
// RefPtr<StringImpl>, with a bit of syntactic sugar.
|
||||
//
|
||||
// Note that StringImpl is an immutable object that cannot shrink or grow.
|
||||
// Its allocation size is snugly tailored to the specific string it contains.
|
||||
|
@ -74,12 +74,12 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
String(RetainPtr<StringImpl>&& impl)
|
||||
String(RefPtr<StringImpl>&& impl)
|
||||
: m_impl(move(impl))
|
||||
{
|
||||
}
|
||||
|
||||
String(Retained<StringImpl>&& impl)
|
||||
String(NonnullRefPtr<StringImpl>&& impl)
|
||||
: m_impl(move(impl))
|
||||
{
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ public:
|
|||
|
||||
private:
|
||||
bool match_helper(const StringView& mask) const;
|
||||
RetainPtr<StringImpl> m_impl;
|
||||
RefPtr<StringImpl> m_impl;
|
||||
};
|
||||
|
||||
inline bool StringView::operator==(const String& string) const
|
||||
|
|
|
@ -10,12 +10,12 @@ namespace AK {
|
|||
|
||||
class ByteBufferImpl : public RefCounted<ByteBufferImpl> {
|
||||
public:
|
||||
static Retained<ByteBufferImpl> create_uninitialized(int size);
|
||||
static Retained<ByteBufferImpl> create_zeroed(int);
|
||||
static Retained<ByteBufferImpl> copy(const void*, int);
|
||||
static Retained<ByteBufferImpl> wrap(void*, int);
|
||||
static Retained<ByteBufferImpl> wrap(const void*, int);
|
||||
static Retained<ByteBufferImpl> adopt(void*, int);
|
||||
static NonnullRefPtr<ByteBufferImpl> create_uninitialized(int size);
|
||||
static NonnullRefPtr<ByteBufferImpl> create_zeroed(int);
|
||||
static NonnullRefPtr<ByteBufferImpl> copy(const void*, int);
|
||||
static NonnullRefPtr<ByteBufferImpl> wrap(void*, int);
|
||||
static NonnullRefPtr<ByteBufferImpl> wrap(const void*, int);
|
||||
static NonnullRefPtr<ByteBufferImpl> adopt(void*, int);
|
||||
|
||||
~ByteBufferImpl() { clear(); }
|
||||
|
||||
|
@ -180,12 +180,12 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
explicit ByteBuffer(RetainPtr<ByteBufferImpl>&& impl)
|
||||
explicit ByteBuffer(RefPtr<ByteBufferImpl>&& impl)
|
||||
: m_impl(move(impl))
|
||||
{
|
||||
}
|
||||
|
||||
RetainPtr<ByteBufferImpl> m_impl;
|
||||
RefPtr<ByteBufferImpl> m_impl;
|
||||
};
|
||||
|
||||
inline ByteBufferImpl::ByteBufferImpl(int size)
|
||||
|
@ -227,34 +227,34 @@ inline void ByteBufferImpl::grow(int size)
|
|||
kfree(old_data);
|
||||
}
|
||||
|
||||
inline Retained<ByteBufferImpl> ByteBufferImpl::create_uninitialized(int size)
|
||||
inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::create_uninitialized(int size)
|
||||
{
|
||||
return ::adopt(*new ByteBufferImpl(size));
|
||||
}
|
||||
|
||||
inline Retained<ByteBufferImpl> ByteBufferImpl::create_zeroed(int size)
|
||||
inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::create_zeroed(int size)
|
||||
{
|
||||
auto buffer = ::adopt(*new ByteBufferImpl(size));
|
||||
memset(buffer->pointer(), 0, size);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
inline Retained<ByteBufferImpl> ByteBufferImpl::copy(const void* data, int size)
|
||||
inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::copy(const void* data, int size)
|
||||
{
|
||||
return ::adopt(*new ByteBufferImpl(data, size, Copy));
|
||||
}
|
||||
|
||||
inline Retained<ByteBufferImpl> ByteBufferImpl::wrap(void* data, int size)
|
||||
inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::wrap(void* data, int size)
|
||||
{
|
||||
return ::adopt(*new ByteBufferImpl(data, size, Wrap));
|
||||
}
|
||||
|
||||
inline Retained<ByteBufferImpl> ByteBufferImpl::wrap(const void* data, int size)
|
||||
inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::wrap(const void* data, int size)
|
||||
{
|
||||
return ::adopt(*new ByteBufferImpl(const_cast<void*>(data), size, Wrap));
|
||||
}
|
||||
|
||||
inline Retained<ByteBufferImpl> ByteBufferImpl::adopt(void* data, int size)
|
||||
inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::adopt(void* data, int size)
|
||||
{
|
||||
return ::adopt(*new ByteBufferImpl(data, size, Adopt));
|
||||
}
|
||||
|
|
|
@ -6,65 +6,65 @@
|
|||
namespace AK {
|
||||
|
||||
template<typename T>
|
||||
class RetainPtr {
|
||||
class RefPtr {
|
||||
public:
|
||||
enum AdoptTag {
|
||||
Adopt
|
||||
};
|
||||
|
||||
RetainPtr() {}
|
||||
RetainPtr(const T* ptr)
|
||||
RefPtr() {}
|
||||
RefPtr(const T* ptr)
|
||||
: m_ptr(const_cast<T*>(ptr))
|
||||
{
|
||||
ref_if_not_null(m_ptr);
|
||||
}
|
||||
RetainPtr(T* ptr)
|
||||
RefPtr(T* ptr)
|
||||
: m_ptr(ptr)
|
||||
{
|
||||
ref_if_not_null(m_ptr);
|
||||
}
|
||||
RetainPtr(T& object)
|
||||
RefPtr(T& object)
|
||||
: m_ptr(&object)
|
||||
{
|
||||
m_ptr->ref();
|
||||
}
|
||||
RetainPtr(const T& object)
|
||||
RefPtr(const T& object)
|
||||
: m_ptr(const_cast<T*>(&object))
|
||||
{
|
||||
m_ptr->ref();
|
||||
}
|
||||
RetainPtr(AdoptTag, T& object)
|
||||
RefPtr(AdoptTag, T& object)
|
||||
: m_ptr(&object)
|
||||
{
|
||||
}
|
||||
RetainPtr(RetainPtr& other)
|
||||
RefPtr(RefPtr& other)
|
||||
: m_ptr(other.copy_ref().leak_ref())
|
||||
{
|
||||
}
|
||||
RetainPtr(RetainPtr&& other)
|
||||
RefPtr(RefPtr&& other)
|
||||
: m_ptr(other.leak_ref())
|
||||
{
|
||||
}
|
||||
template<typename U>
|
||||
RetainPtr(Retained<U>&& other)
|
||||
RefPtr(NonnullRefPtr<U>&& other)
|
||||
: m_ptr(static_cast<T*>(&other.leak_ref()))
|
||||
{
|
||||
}
|
||||
template<typename U>
|
||||
RetainPtr(RetainPtr<U>&& other)
|
||||
RefPtr(RefPtr<U>&& other)
|
||||
: m_ptr(static_cast<T*>(other.leak_ref()))
|
||||
{
|
||||
}
|
||||
RetainPtr(const RetainPtr& other)
|
||||
: m_ptr(const_cast<RetainPtr&>(other).copy_ref().leak_ref())
|
||||
RefPtr(const RefPtr& other)
|
||||
: m_ptr(const_cast<RefPtr&>(other).copy_ref().leak_ref())
|
||||
{
|
||||
}
|
||||
template<typename U>
|
||||
RetainPtr(const RetainPtr<U>& other)
|
||||
: m_ptr(const_cast<RetainPtr<U>&>(other).copy_ref().leak_ref())
|
||||
RefPtr(const RefPtr<U>& other)
|
||||
: m_ptr(const_cast<RefPtr<U>&>(other).copy_ref().leak_ref())
|
||||
{
|
||||
}
|
||||
~RetainPtr()
|
||||
~RefPtr()
|
||||
{
|
||||
clear();
|
||||
#ifdef SANITIZE_PTRS
|
||||
|
@ -74,9 +74,9 @@ public:
|
|||
m_ptr = (T*)(0xe0e0e0e0);
|
||||
#endif
|
||||
}
|
||||
RetainPtr(std::nullptr_t) {}
|
||||
RefPtr(std::nullptr_t) {}
|
||||
|
||||
RetainPtr& operator=(RetainPtr&& other)
|
||||
RefPtr& operator=(RefPtr&& other)
|
||||
{
|
||||
if (this != &other) {
|
||||
deref_if_not_null(m_ptr);
|
||||
|
@ -86,7 +86,7 @@ public:
|
|||
}
|
||||
|
||||
template<typename U>
|
||||
RetainPtr& operator=(RetainPtr<U>&& other)
|
||||
RefPtr& operator=(RefPtr<U>&& other)
|
||||
{
|
||||
if (this != static_cast<void*>(&other)) {
|
||||
deref_if_not_null(m_ptr);
|
||||
|
@ -96,7 +96,7 @@ public:
|
|||
}
|
||||
|
||||
template<typename U>
|
||||
RetainPtr& operator=(Retained<U>&& other)
|
||||
RefPtr& operator=(NonnullRefPtr<U>&& other)
|
||||
{
|
||||
deref_if_not_null(m_ptr);
|
||||
m_ptr = &other.leak_ref();
|
||||
|
@ -104,7 +104,7 @@ public:
|
|||
}
|
||||
|
||||
template<typename U>
|
||||
RetainPtr& operator=(const Retained<U>& other)
|
||||
RefPtr& operator=(const NonnullRefPtr<U>& other)
|
||||
{
|
||||
if (m_ptr != other.ptr())
|
||||
deref_if_not_null(m_ptr);
|
||||
|
@ -115,7 +115,7 @@ public:
|
|||
}
|
||||
|
||||
template<typename U>
|
||||
RetainPtr& operator=(const RetainPtr<U>& other)
|
||||
RefPtr& operator=(const RefPtr<U>& other)
|
||||
{
|
||||
if (m_ptr != other.ptr())
|
||||
deref_if_not_null(m_ptr);
|
||||
|
@ -124,7 +124,7 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
RetainPtr& operator=(const T* ptr)
|
||||
RefPtr& operator=(const T* ptr)
|
||||
{
|
||||
if (m_ptr != ptr)
|
||||
deref_if_not_null(m_ptr);
|
||||
|
@ -133,7 +133,7 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
RetainPtr& operator=(const T& object)
|
||||
RefPtr& operator=(const T& object)
|
||||
{
|
||||
if (m_ptr != &object)
|
||||
deref_if_not_null(m_ptr);
|
||||
|
@ -142,15 +142,15 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
RetainPtr& operator=(std::nullptr_t)
|
||||
RefPtr& operator=(std::nullptr_t)
|
||||
{
|
||||
clear();
|
||||
return *this;
|
||||
}
|
||||
|
||||
RetainPtr copy_ref() const
|
||||
RefPtr copy_ref() const
|
||||
{
|
||||
return RetainPtr(m_ptr);
|
||||
return RefPtr(m_ptr);
|
||||
}
|
||||
|
||||
void clear()
|
||||
|
@ -185,11 +185,11 @@ public:
|
|||
bool operator==(std::nullptr_t) const { return !m_ptr; }
|
||||
bool operator!=(std::nullptr_t) const { return m_ptr; }
|
||||
|
||||
bool operator==(const RetainPtr& other) const { return m_ptr == other.m_ptr; }
|
||||
bool operator!=(const RetainPtr& other) const { return m_ptr != other.m_ptr; }
|
||||
bool operator==(const RefPtr& other) const { return m_ptr == other.m_ptr; }
|
||||
bool operator!=(const RefPtr& other) const { return m_ptr != other.m_ptr; }
|
||||
|
||||
bool operator==(RetainPtr& other) { return m_ptr == other.m_ptr; }
|
||||
bool operator!=(RetainPtr& other) { return m_ptr != other.m_ptr; }
|
||||
bool operator==(RefPtr& other) { return m_ptr == other.m_ptr; }
|
||||
bool operator!=(RefPtr& other) { return m_ptr != other.m_ptr; }
|
||||
|
||||
bool operator==(const T* other) const { return m_ptr == other; }
|
||||
bool operator!=(const T* other) const { return m_ptr != other; }
|
||||
|
@ -205,4 +205,4 @@ private:
|
|||
|
||||
}
|
||||
|
||||
using AK::RetainPtr;
|
||||
using AK::RefPtr;
|
||||
|
|
|
@ -32,58 +32,58 @@ inline void deref_if_not_null(T* ptr)
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
class CONSUMABLE(unconsumed) Retained {
|
||||
class CONSUMABLE(unconsumed) NonnullRefPtr {
|
||||
public:
|
||||
enum AdoptTag {
|
||||
Adopt
|
||||
};
|
||||
|
||||
RETURN_TYPESTATE(unconsumed)
|
||||
Retained(const T& object)
|
||||
NonnullRefPtr(const T& object)
|
||||
: m_ptr(const_cast<T*>(&object))
|
||||
{
|
||||
m_ptr->ref();
|
||||
}
|
||||
template<typename U>
|
||||
RETURN_TYPESTATE(unconsumed)
|
||||
Retained(const U& object)
|
||||
NonnullRefPtr(const U& object)
|
||||
: m_ptr(&const_cast<T&>(static_cast<const T&>(object)))
|
||||
{
|
||||
m_ptr->ref();
|
||||
}
|
||||
RETURN_TYPESTATE(unconsumed)
|
||||
Retained(AdoptTag, T& object)
|
||||
NonnullRefPtr(AdoptTag, T& object)
|
||||
: m_ptr(&object)
|
||||
{
|
||||
}
|
||||
RETURN_TYPESTATE(unconsumed)
|
||||
Retained(Retained& other)
|
||||
NonnullRefPtr(NonnullRefPtr& other)
|
||||
: m_ptr(&other.copy_ref().leak_ref())
|
||||
{
|
||||
}
|
||||
RETURN_TYPESTATE(unconsumed)
|
||||
Retained(Retained&& other)
|
||||
NonnullRefPtr(NonnullRefPtr&& other)
|
||||
: m_ptr(&other.leak_ref())
|
||||
{
|
||||
}
|
||||
template<typename U>
|
||||
RETURN_TYPESTATE(unconsumed)
|
||||
Retained(Retained<U>&& other)
|
||||
NonnullRefPtr(NonnullRefPtr<U>&& other)
|
||||
: m_ptr(static_cast<T*>(&other.leak_ref()))
|
||||
{
|
||||
}
|
||||
RETURN_TYPESTATE(unconsumed)
|
||||
Retained(const Retained& other)
|
||||
: m_ptr(&const_cast<Retained&>(other).copy_ref().leak_ref())
|
||||
NonnullRefPtr(const NonnullRefPtr& other)
|
||||
: m_ptr(&const_cast<NonnullRefPtr&>(other).copy_ref().leak_ref())
|
||||
{
|
||||
}
|
||||
template<typename U>
|
||||
RETURN_TYPESTATE(unconsumed)
|
||||
Retained(const Retained<U>& other)
|
||||
: m_ptr(&const_cast<Retained<U>&>(other).copy_ref().leak_ref())
|
||||
NonnullRefPtr(const NonnullRefPtr<U>& other)
|
||||
: m_ptr(&const_cast<NonnullRefPtr<U>&>(other).copy_ref().leak_ref())
|
||||
{
|
||||
}
|
||||
~Retained()
|
||||
~NonnullRefPtr()
|
||||
{
|
||||
deref_if_not_null(m_ptr);
|
||||
m_ptr = nullptr;
|
||||
|
@ -96,7 +96,7 @@ public:
|
|||
}
|
||||
|
||||
CALLABLE_WHEN(unconsumed)
|
||||
Retained& operator=(Retained&& other)
|
||||
NonnullRefPtr& operator=(NonnullRefPtr&& other)
|
||||
{
|
||||
if (this != &other) {
|
||||
deref_if_not_null(m_ptr);
|
||||
|
@ -107,7 +107,7 @@ public:
|
|||
|
||||
template<typename U>
|
||||
CALLABLE_WHEN(unconsumed)
|
||||
Retained& operator=(Retained<U>&& other)
|
||||
NonnullRefPtr& operator=(NonnullRefPtr<U>&& other)
|
||||
{
|
||||
if (this != static_cast<void*>(&other)) {
|
||||
deref_if_not_null(m_ptr);
|
||||
|
@ -117,7 +117,7 @@ public:
|
|||
}
|
||||
|
||||
CALLABLE_WHEN(unconsumed)
|
||||
Retained& operator=(T& object)
|
||||
NonnullRefPtr& operator=(T& object)
|
||||
{
|
||||
if (m_ptr != &object)
|
||||
deref_if_not_null(m_ptr);
|
||||
|
@ -127,9 +127,9 @@ public:
|
|||
}
|
||||
|
||||
CALLABLE_WHEN(unconsumed)
|
||||
Retained copy_ref() const
|
||||
NonnullRefPtr copy_ref() const
|
||||
{
|
||||
return Retained(*m_ptr);
|
||||
return NonnullRefPtr(*m_ptr);
|
||||
}
|
||||
|
||||
CALLABLE_WHEN(unconsumed)
|
||||
|
@ -208,18 +208,18 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
Retained() {}
|
||||
NonnullRefPtr() {}
|
||||
|
||||
T* m_ptr { nullptr };
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline Retained<T> adopt(T& object)
|
||||
inline NonnullRefPtr<T> adopt(T& object)
|
||||
{
|
||||
return Retained<T>(Retained<T>::Adopt, object);
|
||||
return NonnullRefPtr<T>(NonnullRefPtr<T>::Adopt, object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::adopt;
|
||||
using AK::Retained;
|
||||
using AK::NonnullRefPtr;
|
||||
|
|
|
@ -60,7 +60,7 @@ static inline int allocation_size_for_stringimpl(int length)
|
|||
return sizeof(StringImpl) + (sizeof(char) * length) + sizeof(char);
|
||||
}
|
||||
|
||||
Retained<StringImpl> StringImpl::create_uninitialized(int length, char*& buffer)
|
||||
NonnullRefPtr<StringImpl> StringImpl::create_uninitialized(int length, char*& buffer)
|
||||
{
|
||||
ASSERT(length);
|
||||
void* slot = kmalloc(allocation_size_for_stringimpl(length));
|
||||
|
@ -71,7 +71,7 @@ Retained<StringImpl> StringImpl::create_uninitialized(int length, char*& buffer)
|
|||
return new_stringimpl;
|
||||
}
|
||||
|
||||
RetainPtr<StringImpl> StringImpl::create(const char* cstring, int length, ShouldChomp should_chomp)
|
||||
RefPtr<StringImpl> StringImpl::create(const char* cstring, int length, ShouldChomp should_chomp)
|
||||
{
|
||||
if (!cstring)
|
||||
return nullptr;
|
||||
|
@ -99,7 +99,7 @@ RetainPtr<StringImpl> StringImpl::create(const char* cstring, int length, Should
|
|||
return new_stringimpl;
|
||||
}
|
||||
|
||||
RetainPtr<StringImpl> StringImpl::create(const char* cstring, ShouldChomp shouldChomp)
|
||||
RefPtr<StringImpl> StringImpl::create(const char* cstring, ShouldChomp shouldChomp)
|
||||
{
|
||||
if (!cstring)
|
||||
return nullptr;
|
||||
|
@ -131,7 +131,7 @@ static inline char to_ascii_uppercase(char c)
|
|||
return c;
|
||||
}
|
||||
|
||||
Retained<StringImpl> StringImpl::to_lowercase() const
|
||||
NonnullRefPtr<StringImpl> StringImpl::to_lowercase() const
|
||||
{
|
||||
for (int i = 0; i < m_length; ++i) {
|
||||
if (!is_ascii_lowercase(characters()[i]))
|
||||
|
@ -147,7 +147,7 @@ slow_path:
|
|||
return lowercased;
|
||||
}
|
||||
|
||||
Retained<StringImpl> StringImpl::to_uppercase() const
|
||||
NonnullRefPtr<StringImpl> StringImpl::to_uppercase() const
|
||||
{
|
||||
for (int i = 0; i < m_length; ++i) {
|
||||
if (!is_ascii_uppercase(characters()[i]))
|
||||
|
|
|
@ -14,11 +14,11 @@ enum ShouldChomp {
|
|||
|
||||
class StringImpl : public RefCounted<StringImpl> {
|
||||
public:
|
||||
static Retained<StringImpl> create_uninitialized(int length, char*& buffer);
|
||||
static RetainPtr<StringImpl> create(const char* cstring, ShouldChomp = NoChomp);
|
||||
static RetainPtr<StringImpl> create(const char* cstring, int length, ShouldChomp = NoChomp);
|
||||
Retained<StringImpl> to_lowercase() const;
|
||||
Retained<StringImpl> to_uppercase() const;
|
||||
static NonnullRefPtr<StringImpl> create_uninitialized(int length, char*& buffer);
|
||||
static RefPtr<StringImpl> create(const char* cstring, ShouldChomp = NoChomp);
|
||||
static RefPtr<StringImpl> create(const char* cstring, int length, ShouldChomp = NoChomp);
|
||||
NonnullRefPtr<StringImpl> to_lowercase() const;
|
||||
NonnullRefPtr<StringImpl> to_uppercase() const;
|
||||
|
||||
void operator delete(void* ptr)
|
||||
{
|
||||
|
|
|
@ -50,12 +50,12 @@ public:
|
|||
bool operator==(const OwnPtr<T>& other) const { return ptr() == other.ptr(); }
|
||||
|
||||
private:
|
||||
WeakPtr(RetainPtr<WeakLink<T>>&& link)
|
||||
WeakPtr(RefPtr<WeakLink<T>>&& link)
|
||||
: m_link(move(link))
|
||||
{
|
||||
}
|
||||
|
||||
RetainPtr<WeakLink<T>> m_link;
|
||||
RefPtr<WeakLink<T>> m_link;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
|
|
@ -45,7 +45,7 @@ protected:
|
|||
}
|
||||
|
||||
private:
|
||||
RetainPtr<WeakLink<T>> m_link;
|
||||
RefPtr<WeakLink<T>> m_link;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue