Common: Alloc failures in HeapArray are unlikely

This commit is contained in:
Stenzek 2024-06-28 13:12:50 +10:00
parent a89ec0eaf9
commit dd420cbfcf
No known key found for this signature in database

View file

@ -9,8 +9,8 @@
#include <cassert> #include <cassert>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <type_traits>
#include <span> #include <span>
#include <type_traits>
template<typename T, std::size_t SIZE, std::size_t ALIGNMENT = 0> template<typename T, std::size_t SIZE, std::size_t ALIGNMENT = 0>
class FixedHeapArray class FixedHeapArray
@ -361,10 +361,10 @@ private:
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
m_data = static_cast<T*>(_aligned_realloc(prev_ptr, size * sizeof(T), alignment)); m_data = static_cast<T*>(_aligned_realloc(prev_ptr, size * sizeof(T), alignment));
if (!m_data) if (!m_data) [[unlikely]]
Panic("Memory allocation failed."); Panic("Memory allocation failed.");
#else #else
if (posix_memalign(reinterpret_cast<void**>(&m_data), alignment, size * sizeof(T)) != 0) if (posix_memalign(reinterpret_cast<void**>(&m_data), alignment, size * sizeof(T)) != 0) [[unlikely]]
Panic("Memory allocation failed."); Panic("Memory allocation failed.");
if (prev_ptr) if (prev_ptr)
@ -377,7 +377,7 @@ private:
else else
{ {
m_data = static_cast<T*>(std::realloc(prev_ptr, size * sizeof(T))); m_data = static_cast<T*>(std::realloc(prev_ptr, size * sizeof(T)));
if (!m_data) if (!m_data) [[unlikely]]
Panic("Memory allocation failed."); Panic("Memory allocation failed.");
} }