Skip to content

Commit

Permalink
Common: Alloc failures in HeapArray are unlikely
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jun 28, 2024
1 parent a89ec0e commit dd420cb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/common/heap_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <type_traits>
#include <span>
#include <type_traits>

template<typename T, std::size_t SIZE, std::size_t ALIGNMENT = 0>
class FixedHeapArray
Expand Down Expand Up @@ -361,10 +361,10 @@ class DynamicHeapArray
{
#ifdef _MSC_VER
m_data = static_cast<T*>(_aligned_realloc(prev_ptr, size * sizeof(T), alignment));
if (!m_data)
if (!m_data) [[unlikely]]
Panic("Memory allocation failed.");
#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.");

if (prev_ptr)
Expand All @@ -377,7 +377,7 @@ class DynamicHeapArray
else
{
m_data = static_cast<T*>(std::realloc(prev_ptr, size * sizeof(T)));
if (!m_data)
if (!m_data) [[unlikely]]
Panic("Memory allocation failed.");
}

Expand Down

0 comments on commit dd420cb

Please sign in to comment.