mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:07:36 +00:00
AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to create a NonnullOwnPtr from the result of a naked new.)
This commit is contained in:
parent
b3db01e20e
commit
b91c49364d
228 changed files with 461 additions and 461 deletions
|
@ -292,12 +292,12 @@ inline void ByteBufferImpl::zero_fill()
|
|||
|
||||
inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::create_uninitialized(size_t size)
|
||||
{
|
||||
return ::adopt(*new ByteBufferImpl(size));
|
||||
return ::adopt_ref(*new ByteBufferImpl(size));
|
||||
}
|
||||
|
||||
inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::create_zeroed(size_t size)
|
||||
{
|
||||
auto buffer = ::adopt(*new ByteBufferImpl(size));
|
||||
auto buffer = ::adopt_ref(*new ByteBufferImpl(size));
|
||||
if (size != 0)
|
||||
__builtin_memset(buffer->data(), 0, size);
|
||||
return buffer;
|
||||
|
@ -305,7 +305,7 @@ inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::create_zeroed(size_t size)
|
|||
|
||||
inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::copy(const void* data, size_t size)
|
||||
{
|
||||
return ::adopt(*new ByteBufferImpl(data, size));
|
||||
return ::adopt_ref(*new ByteBufferImpl(data, size));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ Result<NonnullRefPtr<MappedFile>, OSError> MappedFile::map(const String& path)
|
|||
if (ptr == MAP_FAILED)
|
||||
return OSError(errno);
|
||||
|
||||
return adopt(*new MappedFile(ptr, size));
|
||||
return adopt_ref(*new MappedFile(ptr, size));
|
||||
}
|
||||
|
||||
MappedFile::MappedFile(void* ptr, size_t size)
|
||||
|
|
|
@ -314,7 +314,7 @@ private:
|
|||
};
|
||||
|
||||
template<typename T>
|
||||
inline NonnullRefPtr<T> adopt(T& object)
|
||||
inline NonnullRefPtr<T> adopt_ref(T& object)
|
||||
{
|
||||
return NonnullRefPtr<T>(NonnullRefPtr<T>::Adopt, object);
|
||||
}
|
||||
|
@ -335,5 +335,5 @@ inline void swap(NonnullRefPtr<T>& a, NonnullRefPtr<U>& b)
|
|||
|
||||
}
|
||||
|
||||
using AK::adopt;
|
||||
using AK::adopt_ref;
|
||||
using AK::NonnullRefPtr;
|
||||
|
|
|
@ -71,7 +71,7 @@ NonnullRefPtr<StringImpl> StringImpl::create_uninitialized(size_t length, char*&
|
|||
VERIFY(length);
|
||||
void* slot = kmalloc(allocation_size_for_stringimpl(length));
|
||||
VERIFY(slot);
|
||||
auto new_stringimpl = adopt(*new (slot) StringImpl(ConstructWithInlineBuffer, length));
|
||||
auto new_stringimpl = adopt_ref(*new (slot) StringImpl(ConstructWithInlineBuffer, length));
|
||||
buffer = const_cast<char*>(new_stringimpl->characters());
|
||||
buffer[length] = '\0';
|
||||
return new_stringimpl;
|
||||
|
|
|
@ -239,25 +239,25 @@ using AK::TestSuite;
|
|||
#define __TESTCASE_FUNC(x) __test_##x
|
||||
#define __TESTCASE_TYPE(x) __TestCase_##x
|
||||
|
||||
#define TEST_CASE(x) \
|
||||
static void __TESTCASE_FUNC(x)(); \
|
||||
struct __TESTCASE_TYPE(x) { \
|
||||
__TESTCASE_TYPE(x) \
|
||||
() { TestSuite::the().add_case(adopt(*new TestCase(#x, __TESTCASE_FUNC(x), false))); } \
|
||||
}; \
|
||||
static struct __TESTCASE_TYPE(x) __TESTCASE_TYPE(x); \
|
||||
#define TEST_CASE(x) \
|
||||
static void __TESTCASE_FUNC(x)(); \
|
||||
struct __TESTCASE_TYPE(x) { \
|
||||
__TESTCASE_TYPE(x) \
|
||||
() { TestSuite::the().add_case(adopt_ref(*new TestCase(#x, __TESTCASE_FUNC(x), false))); } \
|
||||
}; \
|
||||
static struct __TESTCASE_TYPE(x) __TESTCASE_TYPE(x); \
|
||||
static void __TESTCASE_FUNC(x)()
|
||||
|
||||
#define __BENCHMARK_FUNC(x) __benchmark_##x
|
||||
#define __BENCHMARK_TYPE(x) __BenchmarkCase_##x
|
||||
|
||||
#define BENCHMARK_CASE(x) \
|
||||
static void __BENCHMARK_FUNC(x)(); \
|
||||
struct __BENCHMARK_TYPE(x) { \
|
||||
__BENCHMARK_TYPE(x) \
|
||||
() { TestSuite::the().add_case(adopt(*new TestCase(#x, __BENCHMARK_FUNC(x), true))); } \
|
||||
}; \
|
||||
static struct __BENCHMARK_TYPE(x) __BENCHMARK_TYPE(x); \
|
||||
#define BENCHMARK_CASE(x) \
|
||||
static void __BENCHMARK_FUNC(x)(); \
|
||||
struct __BENCHMARK_TYPE(x) { \
|
||||
__BENCHMARK_TYPE(x) \
|
||||
() { TestSuite::the().add_case(adopt_ref(*new TestCase(#x, __BENCHMARK_FUNC(x), true))); } \
|
||||
}; \
|
||||
static struct __BENCHMARK_TYPE(x) __BENCHMARK_TYPE(x); \
|
||||
static void __BENCHMARK_FUNC(x)()
|
||||
|
||||
#define TEST_MAIN(x) \
|
||||
|
|
|
@ -60,7 +60,7 @@ using IntrusiveRefPtrList = IntrusiveList<IntrusiveRefPtrItem, RefPtr<IntrusiveR
|
|||
|
||||
TEST_CASE(intrusive_ref_ptr_no_ref_leaks)
|
||||
{
|
||||
auto item = adopt(*new IntrusiveRefPtrItem());
|
||||
auto item = adopt_ref(*new IntrusiveRefPtrItem());
|
||||
EXPECT_EQ(1u, item->ref_count());
|
||||
IntrusiveRefPtrList ref_list;
|
||||
|
||||
|
@ -73,7 +73,7 @@ TEST_CASE(intrusive_ref_ptr_no_ref_leaks)
|
|||
|
||||
TEST_CASE(intrusive_ref_ptr_clear)
|
||||
{
|
||||
auto item = adopt(*new IntrusiveRefPtrItem());
|
||||
auto item = adopt_ref(*new IntrusiveRefPtrItem());
|
||||
EXPECT_EQ(1u, item->ref_count());
|
||||
IntrusiveRefPtrList ref_list;
|
||||
|
||||
|
@ -86,7 +86,7 @@ TEST_CASE(intrusive_ref_ptr_clear)
|
|||
|
||||
TEST_CASE(intrusive_ref_ptr_destructor)
|
||||
{
|
||||
auto item = adopt(*new IntrusiveRefPtrItem());
|
||||
auto item = adopt_ref(*new IntrusiveRefPtrItem());
|
||||
EXPECT_EQ(1u, item->ref_count());
|
||||
|
||||
{
|
||||
|
@ -107,7 +107,7 @@ using IntrusiveNonnullRefPtrList = IntrusiveList<IntrusiveNonnullRefPtrItem, Non
|
|||
|
||||
TEST_CASE(intrusive_nonnull_ref_ptr_intrusive)
|
||||
{
|
||||
auto item = adopt(*new IntrusiveNonnullRefPtrItem());
|
||||
auto item = adopt_ref(*new IntrusiveNonnullRefPtrItem());
|
||||
EXPECT_EQ(1u, item->ref_count());
|
||||
IntrusiveNonnullRefPtrList nonnull_ref_list;
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ struct Object : public RefCounted<Object> {
|
|||
|
||||
TEST_CASE(basics)
|
||||
{
|
||||
auto object = adopt(*new Object);
|
||||
auto object = adopt_ref(*new Object);
|
||||
EXPECT(object.ptr() != nullptr);
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
object->ref();
|
||||
|
@ -33,7 +33,7 @@ TEST_CASE(basics)
|
|||
|
||||
TEST_CASE(assign_reference)
|
||||
{
|
||||
auto object = adopt(*new Object);
|
||||
auto object = adopt_ref(*new Object);
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
object = *object;
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
|
@ -45,8 +45,8 @@ TEST_CASE(assign_owner_of_self)
|
|||
RefPtr<Object> parent;
|
||||
};
|
||||
|
||||
auto parent = adopt(*new Object);
|
||||
auto child = adopt(*new Object);
|
||||
auto parent = adopt_ref(*new Object);
|
||||
auto child = adopt_ref(*new Object);
|
||||
child->parent = move(parent);
|
||||
|
||||
child = *child->parent;
|
||||
|
@ -55,7 +55,7 @@ TEST_CASE(assign_owner_of_self)
|
|||
|
||||
TEST_CASE(swap_with_self)
|
||||
{
|
||||
auto object = adopt(*new Object);
|
||||
auto object = adopt_ref(*new Object);
|
||||
swap(object, object);
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ size_t SelfAwareObject::num_destroyed = 0;
|
|||
|
||||
TEST_CASE(basics)
|
||||
{
|
||||
RefPtr<Object> object = adopt(*new Object);
|
||||
RefPtr<Object> object = adopt_ref(*new Object);
|
||||
EXPECT(object.ptr() != nullptr);
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
object->ref();
|
||||
|
@ -45,7 +45,7 @@ TEST_CASE(basics)
|
|||
|
||||
TEST_CASE(assign_reference)
|
||||
{
|
||||
RefPtr<Object> object = adopt(*new Object);
|
||||
RefPtr<Object> object = adopt_ref(*new Object);
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
object = *object;
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
|
@ -53,7 +53,7 @@ TEST_CASE(assign_reference)
|
|||
|
||||
TEST_CASE(assign_ptr)
|
||||
{
|
||||
RefPtr<Object> object = adopt(*new Object);
|
||||
RefPtr<Object> object = adopt_ref(*new Object);
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
object = object.ptr();
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
|
@ -61,7 +61,7 @@ TEST_CASE(assign_ptr)
|
|||
|
||||
TEST_CASE(copy_move_ref)
|
||||
{
|
||||
RefPtr<Object2> object = adopt(*new Object2);
|
||||
RefPtr<Object2> object = adopt_ref(*new Object2);
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
{
|
||||
auto object2 = object;
|
||||
|
@ -84,8 +84,8 @@ TEST_CASE(copy_move_ref)
|
|||
|
||||
TEST_CASE(swap)
|
||||
{
|
||||
RefPtr<Object> object_a = adopt(*new Object);
|
||||
RefPtr<Object> object_b = adopt(*new Object);
|
||||
RefPtr<Object> object_a = adopt_ref(*new Object);
|
||||
RefPtr<Object> object_b = adopt_ref(*new Object);
|
||||
auto* ptr_a = object_a.ptr();
|
||||
auto* ptr_b = object_b.ptr();
|
||||
swap(object_a, object_b);
|
||||
|
@ -97,7 +97,7 @@ TEST_CASE(swap)
|
|||
|
||||
TEST_CASE(assign_moved_self)
|
||||
{
|
||||
RefPtr<Object> object = adopt(*new Object);
|
||||
RefPtr<Object> object = adopt_ref(*new Object);
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
#ifdef __clang__
|
||||
# pragma clang diagnostic push
|
||||
|
@ -112,7 +112,7 @@ TEST_CASE(assign_moved_self)
|
|||
|
||||
TEST_CASE(assign_copy_self)
|
||||
{
|
||||
RefPtr<Object> object = adopt(*new Object);
|
||||
RefPtr<Object> object = adopt_ref(*new Object);
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
|
||||
#ifdef __clang__
|
||||
|
@ -129,7 +129,7 @@ TEST_CASE(assign_copy_self)
|
|||
|
||||
TEST_CASE(self_observers)
|
||||
{
|
||||
RefPtr<SelfAwareObject> object = adopt(*new SelfAwareObject);
|
||||
RefPtr<SelfAwareObject> object = adopt_ref(*new SelfAwareObject);
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
EXPECT_EQ(object->m_has_one_ref_left, false);
|
||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
||||
|
|
|
@ -34,7 +34,7 @@ TEST_CASE(basic_weak)
|
|||
WeakPtr<SimpleWeakable> weak2;
|
||||
|
||||
{
|
||||
auto simple = adopt(*new SimpleWeakable);
|
||||
auto simple = adopt_ref(*new SimpleWeakable);
|
||||
weak1 = simple;
|
||||
weak2 = simple;
|
||||
EXPECT_EQ(weak1.is_null(), false);
|
||||
|
@ -54,7 +54,7 @@ TEST_CASE(weakptr_move)
|
|||
WeakPtr<SimpleWeakable> weak2;
|
||||
|
||||
{
|
||||
auto simple = adopt(*new SimpleWeakable);
|
||||
auto simple = adopt_ref(*new SimpleWeakable);
|
||||
weak1 = simple;
|
||||
weak2 = move(weak1);
|
||||
EXPECT_EQ(weak1.is_null(), true);
|
||||
|
|
|
@ -198,7 +198,7 @@ inline WeakPtr<U> Weakable<T>::make_weak_ptr() const
|
|||
// There is a small chance that we create a new WeakLink and throw
|
||||
// it away because another thread beat us to it. But the window is
|
||||
// pretty small and the overhead isn't terrible.
|
||||
m_link.assign_if_null(adopt(*new WeakLink(const_cast<T&>(static_cast<const T&>(*this)))));
|
||||
m_link.assign_if_null(adopt_ref(*new WeakLink(const_cast<T&>(static_cast<const T&>(*this)))));
|
||||
}
|
||||
|
||||
WeakPtr<U> weak_ptr(m_link);
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
if (!(m_consumers.fetch_add(1u << 1, AK::MemoryOrder::memory_order_acquire) & 1u)) {
|
||||
T* ptr = (T*)m_ptr.load(AK::MemoryOrder::memory_order_acquire);
|
||||
if (ptr && ptr->try_ref())
|
||||
ref = adopt(*ptr);
|
||||
ref = adopt_ref(*ptr);
|
||||
}
|
||||
m_consumers.fetch_sub(1u << 1, AK::MemoryOrder::memory_order_release);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue