AK: Remove custom deleters from OwnPtr
OwnPtr now always deletes the owned object directly from clear(). Remove the unused deleter template parameter and the DefaultDelete helper that only supported that parameter. Drop the dedicated custom deleter test.
This commit is contained in:
parent
0fca7d1a6e
commit
079af3d120
4 changed files with 3 additions and 53 deletions
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace AK {
|
||||
|
||||
template<class T>
|
||||
struct DefaultDelete {
|
||||
constexpr DefaultDelete() = default;
|
||||
|
||||
constexpr void operator()(T* t)
|
||||
{
|
||||
delete t;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct DefaultDelete<T[]> {
|
||||
constexpr DefaultDelete() = default;
|
||||
|
||||
constexpr void operator()(T* t)
|
||||
{
|
||||
delete[] t;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#ifdef USING_AK_GLOBALLY
|
||||
using AK::DefaultDelete;
|
||||
#endif
|
||||
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/DefaultDelete.h>
|
||||
#include <AK/SinglyLinkedListSizePolicy.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/Types.h>
|
||||
|
|
@ -148,7 +147,7 @@ class Optional<FlyString>;
|
|||
template<typename T>
|
||||
class RefPtr;
|
||||
|
||||
template<typename T, typename TDeleter = DefaultDelete<T>>
|
||||
template<typename T>
|
||||
class OwnPtr;
|
||||
|
||||
template<typename T>
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
namespace AK {
|
||||
|
||||
template<typename T, typename TDeleter>
|
||||
template<typename T>
|
||||
class [[nodiscard]] OwnPtr {
|
||||
public:
|
||||
OwnPtr() = default;
|
||||
|
|
@ -107,7 +107,7 @@ public:
|
|||
void clear()
|
||||
{
|
||||
auto* ptr = exchange(m_ptr, nullptr);
|
||||
TDeleter {}(ptr);
|
||||
delete ptr;
|
||||
}
|
||||
|
||||
bool operator!() const { return !m_ptr; }
|
||||
|
|
|
|||
|
|
@ -8,20 +8,6 @@
|
|||
|
||||
#include <AK/OwnPtr.h>
|
||||
|
||||
static u64 deleter_call_count = 0;
|
||||
|
||||
TEST_CASE(should_call_custom_deleter)
|
||||
{
|
||||
auto deleter = [](auto* p) { if (p) ++deleter_call_count; };
|
||||
auto ptr = OwnPtr<u64, decltype(deleter)> {};
|
||||
ptr.clear();
|
||||
EXPECT_EQ(0u, deleter_call_count);
|
||||
ptr = adopt_own_if_nonnull(&deleter_call_count);
|
||||
EXPECT_EQ(0u, deleter_call_count);
|
||||
ptr.clear();
|
||||
EXPECT_EQ(1u, deleter_call_count);
|
||||
}
|
||||
|
||||
TEST_CASE(destroy_self_owning_object)
|
||||
{
|
||||
struct SelfOwning {
|
||||
|
|
|
|||
Loading…
Reference in a new issue