Skip to content

Commit 5f8f005

Browse files
performance: Correct alignment checks
Only use checks in debug builds. Resolves: HSD-18039597713 Signed-off-by: Filip Hazubski <[email protected]> Source: 7d16521
1 parent 6151482 commit 5f8f005

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

shared/source/helpers/aligned_memory.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
template <typename T, typename TNoRef = typename std::remove_reference<T>::type>
2424
constexpr inline TNoRef alignUp(T before, size_t alignment) {
25-
UNRECOVERABLE_IF(!Math::isPow2(alignment));
25+
OPTIONAL_UNRECOVERABLE_IF(!Math::isPow2(alignment));
2626
TNoRef mask = static_cast<TNoRef>(alignment - 1);
2727
return (before + mask) & ~mask;
2828
}
@@ -43,7 +43,7 @@ constexpr inline T *alignUp(T *ptrBefore, size_t alignment) {
4343

4444
template <typename T, typename TNoRef = typename std::remove_reference<T>::type>
4545
constexpr inline TNoRef alignDown(T before, size_t alignment) {
46-
UNRECOVERABLE_IF(!Math::isPow2(alignment));
46+
OPTIONAL_UNRECOVERABLE_IF(!Math::isPow2(alignment));
4747
TNoRef mask = static_cast<TNoRef>(alignment - 1);
4848
return before & ~mask;
4949
}
@@ -108,7 +108,7 @@ inline bool isAligned(T *ptr) {
108108

109109
template <typename T1, typename T2>
110110
inline bool isAligned(T1 ptr, T2 alignment) {
111-
UNRECOVERABLE_IF(!Math::isPow2(alignment));
111+
OPTIONAL_UNRECOVERABLE_IF(!Math::isPow2(alignment));
112112
return ((static_cast<size_t>(ptr)) & (static_cast<size_t>(alignment) - 1u)) == 0;
113113
}
114114

shared/source/helpers/debug_helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#define UNREACHABLE(...) std::abort()
1717

18-
#ifdef MOCKABLE
18+
#if defined(MOCKABLE) || defined(_DEBUG)
1919
#define OPTIONAL_UNRECOVERABLE_IF(expression) UNRECOVERABLE_IF(expression)
2020
#else
2121
#define OPTIONAL_UNRECOVERABLE_IF(expression) (void)0

0 commit comments

Comments
 (0)