ams: replace most remaining operator & with std::addressof

This commit is contained in:
Michael Scire
2021-10-09 14:49:53 -07:00
parent ce8aacef21
commit 1ab0bd1765
109 changed files with 587 additions and 586 deletions

View File

@@ -43,11 +43,11 @@ namespace ams::lmem::impl {
}
constexpr inline ExpHeapHead *GetExpHeapHead(HeapHead *heap_head) {
return &heap_head->impl_head.exp_heap_head;
return std::addressof(heap_head->impl_head.exp_heap_head);
}
constexpr inline const ExpHeapHead *GetExpHeapHead(const HeapHead *heap_head) {
return &heap_head->impl_head.exp_heap_head;
return std::addressof(heap_head->impl_head.exp_heap_head);
}
constexpr inline HeapHead *GetHeapHead(ExpHeapHead *exp_heap_head) {
@@ -197,7 +197,7 @@ namespace ams::lmem::impl {
/* Locate the block. */
for (auto it = head->free_list.begin(); it != head->free_list.end(); it++) {
ExpHeapMemoryBlockHead *cur_free_block = &*it;
ExpHeapMemoryBlockHead *cur_free_block = std::addressof(*it);
if (cur_free_block < region->start) {
prev_free_block_it = it;
@@ -220,9 +220,9 @@ namespace ams::lmem::impl {
auto insertion_it = head->free_list.begin();
if (prev_free_block_it != head->free_list.end()) {
/* There's a previous free block, so we want to insert as the next iterator. */
if (GetMemoryBlockEnd(&*prev_free_block_it) == region->start) {
if (GetMemoryBlockEnd(std::addressof(*prev_free_block_it)) == region->start) {
/* We can coalesce, so do so. */
free_region.start = &*prev_free_block_it;
free_region.start = std::addressof(*prev_free_block_it);
insertion_it = head->free_list.erase(prev_free_block_it);
} else {
/* We can't coalesce, so just select the next iterator. */
@@ -249,7 +249,7 @@ namespace ams::lmem::impl {
void *ConvertFreeBlockToUsedBlock(ExpHeapHead *head, ExpHeapMemoryBlockHead *block_head, void *block, size_t size, AllocationDirection direction) {
/* Calculate freed memory regions. */
MemoryRegion free_region_front;
GetMemoryBlockRegion(&free_region_front, block_head);
GetMemoryBlockRegion(std::addressof(free_region_front), block_head);
MemoryRegion free_region_back{ .start = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(block) + size), .end = free_region_front.end, };
/* Adjust end of head region. */
@@ -308,12 +308,12 @@ namespace ams::lmem::impl {
size_t best_size = std::numeric_limits<size_t>::max();
for (auto it = exp_heap_head->free_list.begin(); it != exp_heap_head->free_list.end(); it++) {
const uintptr_t absolute_block_start = reinterpret_cast<uintptr_t>(GetMemoryBlockStart(&*it));
const uintptr_t absolute_block_start = reinterpret_cast<uintptr_t>(GetMemoryBlockStart(std::addressof(*it)));
const uintptr_t block_start = util::AlignUp(absolute_block_start, alignment);
const size_t block_offset = block_start - absolute_block_start;
if (it->block_size >= size + block_offset && best_size > it->block_size) {
found_block_head = &*it;
found_block_head = std::addressof(*it);
found_block = reinterpret_cast<void *>(block_start);
best_size = it->block_size;
@@ -342,12 +342,12 @@ namespace ams::lmem::impl {
size_t best_size = std::numeric_limits<size_t>::max();
for (auto it = exp_heap_head->free_list.rbegin(); it != exp_heap_head->free_list.rend(); it++) {
const uintptr_t absolute_block_start = reinterpret_cast<uintptr_t>(GetMemoryBlockStart(&*it));
const uintptr_t absolute_block_start = reinterpret_cast<uintptr_t>(GetMemoryBlockStart(std::addressof(*it)));
const uintptr_t block_start = util::AlignUp(absolute_block_start, alignment);
const size_t block_offset = block_start - absolute_block_start;
if (it->block_size >= size + block_offset && best_size > it->block_size) {
found_block_head = &*it;
found_block_head = std::addressof(*it);
found_block = reinterpret_cast<void *>(block_start);
best_size = it->block_size;
@@ -396,7 +396,7 @@ namespace ams::lmem::impl {
}
/* Get the memory block end, make sure it really is the last block. */
ExpHeapMemoryBlockHead *block = &exp_heap_head->free_list.back();
ExpHeapMemoryBlockHead *block = std::addressof(exp_heap_head->free_list.back());
void * const block_start = GetMemoryBlockStart(block);
const size_t block_size = block->block_size;
void * const block_end = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(block_start) + block_size);
@@ -460,11 +460,11 @@ namespace ams::lmem::impl {
MemoryRegion region;
/* Erase the heap from the used list, and coalesce it with adjacent blocks. */
GetMemoryBlockRegion(&region, block);
GetMemoryBlockRegion(std::addressof(region), block);
exp_heap_head->used_list.erase(exp_heap_head->used_list.iterator_to(*block));
/* Coalesce with adjacent blocks. */
const bool coalesced = CoalesceFreedRegion(exp_heap_head, &region);
const bool coalesced = CoalesceFreedRegion(exp_heap_head, std::addressof(region));
AMS_ASSERT(coalesced);
AMS_UNUSED(coalesced);
}
@@ -493,8 +493,8 @@ namespace ams::lmem::impl {
ExpHeapMemoryBlockHead *next_block_head = nullptr;
for (auto it = exp_heap_head->free_list.begin(); it != exp_heap_head->free_list.end(); it++) {
if (&*it == cur_block_end) {
next_block_head = &*it;
if (std::addressof(*it) == cur_block_end) {
next_block_head = std::addressof(*it);
break;
}
}
@@ -508,7 +508,7 @@ namespace ams::lmem::impl {
{
/* Get block region. */
MemoryRegion new_free_region;
GetMemoryBlockRegion(&new_free_region, next_block_head);
GetMemoryBlockRegion(std::addressof(new_free_region), next_block_head);
/* Remove the next block from the free list. */
auto insertion_it = exp_heap_head->free_list.erase(exp_heap_head->free_list.iterator_to(*next_block_head));
@@ -539,7 +539,7 @@ namespace ams::lmem::impl {
/* Try to free the new memory. */
block_head->block_size = size;
if (!CoalesceFreedRegion(exp_heap_head, &new_free_region)) {
if (!CoalesceFreedRegion(exp_heap_head, std::addressof(new_free_region))) {
/* We didn't shrink the block successfully, so restore the size. */
block_head->block_size = original_block_size;
}
@@ -567,9 +567,9 @@ namespace ams::lmem::impl {
size_t max_size = std::numeric_limits<size_t>::min();
size_t min_offset = std::numeric_limits<size_t>::max();
for (const auto &it : GetExpHeapHead(handle)->free_list) {
const uintptr_t absolute_block_start = reinterpret_cast<uintptr_t>(GetMemoryBlockStart(&it));
const uintptr_t absolute_block_start = reinterpret_cast<uintptr_t>(GetMemoryBlockStart(std::addressof(it)));
const uintptr_t block_start = util::AlignUp(absolute_block_start, alignment);
const uintptr_t block_end = reinterpret_cast<uintptr_t>(GetMemoryBlockEnd(&it));
const uintptr_t block_end = reinterpret_cast<uintptr_t>(GetMemoryBlockEnd(std::addressof(it)));
if (block_start < block_end) {
const size_t block_size = GetPointerDifference(block_start, block_end);
@@ -620,7 +620,7 @@ namespace ams::lmem::impl {
AMS_ASSERT(IsValidHeapHandle(handle));
for (auto &it : GetExpHeapHead(handle)->used_list) {
(*visitor)(GetMemoryBlockStart(&it), handle, user_data);
(*visitor)(GetMemoryBlockStart(std::addressof(it)), handle, user_data);
}
}