[ox] Correct bad bit_cast uses and improve constexpr-ness
This commit is contained in:
18
deps/ox/src/ox/std/heapmgr.cpp
vendored
18
deps/ox/src/ox/std/heapmgr.cpp
vendored
@@ -25,29 +25,29 @@ static constexpr std::size_t alignedSize(T = {}) noexcept {
|
||||
return alignedSize(sizeof(T));
|
||||
}
|
||||
|
||||
void HeapSegment::init(std::size_t maxSize = bit_cast<std::size_t>(g_heapEnd)) noexcept {
|
||||
this->size = maxSize - bit_cast<std::size_t>(this);
|
||||
void HeapSegment::init(std::size_t maxSize = std::bit_cast<std::size_t>(g_heapEnd)) noexcept {
|
||||
this->size = maxSize - std::bit_cast<std::size_t>(this);
|
||||
this->inUse = false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *HeapSegment::data() noexcept {
|
||||
return bit_cast<T*>(bit_cast<uint8_t*>(this) + alignedSize(this));
|
||||
return reinterpret_cast<T*>(reinterpret_cast<uint8_t*>(this) + alignedSize(this));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *HeapSegment::end() noexcept {
|
||||
const auto size = alignedSize(this) + alignedSize(this->size);
|
||||
auto e = bit_cast<uintptr_t>(bit_cast<uint8_t*>(this) + size);
|
||||
return bit_cast<T*>(e);
|
||||
auto e = std::bit_cast<uintptr_t>(reinterpret_cast<uint8_t*>(this) + size);
|
||||
return reinterpret_cast<T*>(e);
|
||||
}
|
||||
|
||||
|
||||
void initHeap(char *heapBegin, char *heapEnd) noexcept {
|
||||
g_heapBegin = bit_cast<HeapSegment*>(heapBegin);
|
||||
g_heapEnd = bit_cast<HeapSegment*>(heapEnd);
|
||||
void initHeap(void *heapBegin, void *heapEnd) noexcept {
|
||||
g_heapBegin = reinterpret_cast<HeapSegment*>(heapBegin);
|
||||
g_heapEnd = reinterpret_cast<HeapSegment*>(heapEnd);
|
||||
heapIdx = g_heapBegin;
|
||||
heapIdx->size = bit_cast<std::size_t>(heapEnd) - bit_cast<std::size_t>(heapIdx);
|
||||
heapIdx->size = std::bit_cast<std::size_t>(heapEnd) - std::bit_cast<std::size_t>(heapIdx);
|
||||
heapIdx->inUse = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user