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

@ -30,8 +30,8 @@ namespace ams::lmem::impl {
void InitializeHeapHead(HeapHead *out, u32 magic, void *start, void *end, u32 option) {
/* Call member constructors. */
new (&out->list_node) util::IntrusiveListNode;
new (&out->child_list) decltype(out->child_list);
std::construct_at(std::addressof(out->list_node));
std::construct_at(std::addressof(out->child_list));
/* Set fields. */
out->magic = magic;

View file

@ -147,12 +147,11 @@ namespace ams::lmem::impl {
}
inline ExpHeapMemoryBlockHead *InitializeMemoryBlock(const MemoryRegion &region, u16 magic) {
ExpHeapMemoryBlockHead *block = reinterpret_cast<ExpHeapMemoryBlockHead *>(region.start);
/* Construct the block. */
ExpHeapMemoryBlockHead *block = std::construct_at(reinterpret_cast<ExpHeapMemoryBlockHead *>(region.start));
/* Ensure all member constructors are called. */
new (block) ExpHeapMemoryBlockHead;
block->magic = magic;
/* Initialize all members. */
block->magic = magic;
block->attributes = 0;
block->block_size = GetPointerDifference(GetMemoryBlockStart(block), region.end);
@ -175,8 +174,8 @@ namespace ams::lmem::impl {
InitializeHeapHead(heap_head, ExpHeapMagic, GetExpHeapMemoryStart(exp_heap_head), end, option);
/* Call exp heap member constructors. */
new (&exp_heap_head->free_list) ExpHeapMemoryBlockList;
new (&exp_heap_head->used_list) ExpHeapMemoryBlockList;
std::construct_at(std::addressof(exp_heap_head->free_list));
std::construct_at(std::addressof(exp_heap_head->used_list));
/* Set exp heap fields. */
exp_heap_head->group_id = DefaultGroupId;