mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC
Allow a `std::unique_ptr` to be moved into the an `IntrusiveRefCntPtr`, and remove a couple of now-unnecessary `release()` calls. Differential Revision: https://reviews.llvm.org/D92888
This commit is contained in:
parent
2b916be8fe
commit
7308ff63ab
@ -58,6 +58,7 @@
|
||||
#include <atomic>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
namespace llvm {
|
||||
|
||||
@ -175,6 +176,11 @@ public:
|
||||
S.Obj = nullptr;
|
||||
}
|
||||
|
||||
template <class X>
|
||||
IntrusiveRefCntPtr(std::unique_ptr<X> S) : Obj(S.release()) {
|
||||
retain();
|
||||
}
|
||||
|
||||
template <class X>
|
||||
IntrusiveRefCntPtr(const IntrusiveRefCntPtr<X> &S) : Obj(S.get()) {
|
||||
retain();
|
||||
|
@ -42,6 +42,17 @@ TYPED_TEST(IntrusiveRefCntPtrTest, RefCountedBaseCopyDoesNotLeak) {
|
||||
EXPECT_EQ(0, NumInstances);
|
||||
}
|
||||
|
||||
TYPED_TEST(IntrusiveRefCntPtrTest, InteropsWithUniquePtr) {
|
||||
EXPECT_EQ(0, NumInstances);
|
||||
{
|
||||
auto S1 = std::make_unique<TypeParam>();
|
||||
IntrusiveRefCntPtr<TypeParam> R1 = std::move(S1);
|
||||
EXPECT_EQ(1, NumInstances);
|
||||
EXPECT_EQ(S1, nullptr);
|
||||
}
|
||||
EXPECT_EQ(0, NumInstances);
|
||||
}
|
||||
|
||||
struct InterceptRefCounted : public RefCountedBase<InterceptRefCounted> {
|
||||
InterceptRefCounted(bool *Released, bool *Retained)
|
||||
: Released(Released), Retained(Retained) {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user