ams: prefer construct_at/destroy_at over placement new/explicit destructor

This commit is contained in:
Michael Scire
2021-03-21 20:30:40 -07:00
parent aff0da9427
commit d84dcb653d
49 changed files with 217 additions and 171 deletions

View File

@@ -80,7 +80,7 @@ namespace ams::ddsf {
DeviceCodeEntry &Construct(DeviceCode dc, IDevice *dev) {
AMS_ASSERT(!this->IsConstructed());
DeviceCodeEntry *entry = new (GetPointer(this->entry_storage)) DeviceCodeEntry(dc, dev);
DeviceCodeEntry *entry = util::ConstructAt(this->entry_storage, dc, dev);
this->is_constructed = true;
return *entry;
}
@@ -91,7 +91,7 @@ namespace ams::ddsf {
void Destroy() {
AMS_ASSERT(this->IsConstructed());
GetReference(this->entry_storage).~DeviceCodeEntry();
util::DestroyAt(this->entry_storage);
this->is_constructed = false;
}

View File

@@ -127,7 +127,8 @@ namespace ams::sf::cmif {
if (storage == nullptr) {
return nullptr;
}
return new (storage) Domain(this);
return std::construct_at(static_cast<Domain *>(storage), this);
}
public:
static void DestroyDomainServiceObject(DomainServiceObject *obj) {

View File

@@ -732,12 +732,12 @@ namespace ams::sf::impl {
template<size_t Index, typename Interface>
SharedPointer<Interface> *GetOutObjectSharedPointer() {
static_assert(sizeof(SharedPointer<Interface>) == sizeof(SharedPointer<sf::IServiceObject>));
return static_cast<SharedPointer<Interface> *>(static_cast<void *>(&out_shared_pointers[Index]));
return static_cast<SharedPointer<Interface> *>(static_cast<void *>(GetPointer(out_shared_pointers[Index])));
}
template<size_t Index, typename Interface>
Out<SharedPointer<Interface>> GetOutObject() {
auto sp = new (GetOutObjectSharedPointer<Index, Interface>()) SharedPointer<Interface>;
auto sp = std::construct_at(GetOutObjectSharedPointer<Index, Interface>());
return Out<SharedPointer<Interface>>(sp, &this->out_object_ids[Index]);
}

View File

@@ -113,7 +113,7 @@ namespace ams::sf {
void DisposeImpl() {
Allocator *a = this->GetAllocator();
this->~Object();
std::destroy_at(this);
operator delete(this, a);
}
public: