mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-31 22:15:33 +00:00
Add align implementation
This commit is contained in:
parent
b477775e16
commit
d2c2bdadb5
2 changed files with 13 additions and 1 deletions
|
@ -85,6 +85,18 @@ namespace DetourNavigator
|
|||
{
|
||||
return static_cast<std::size_t*>(ptr) + 1;
|
||||
}
|
||||
|
||||
// TODO: use std::align
|
||||
inline void* align(std::size_t align, std::size_t size, void*& ptr, std::size_t& space) noexcept
|
||||
{
|
||||
const auto intptr = reinterpret_cast<std::uintptr_t>(ptr);
|
||||
const auto aligned = (intptr - 1u + align) & - align;
|
||||
const auto diff = aligned - intptr;
|
||||
if ((size + diff) > space)
|
||||
return nullptr;
|
||||
space -= diff;
|
||||
return ptr = reinterpret_cast<void*>(aligned);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace DetourNavigator
|
|||
std::size_t space = mStack.size() - getUsedSize();
|
||||
void* top = mTop;
|
||||
const auto itemSize = 2 * sizeof(std::size_t) + size;
|
||||
if (rcUnlikely(!std::align(sizeof(std::size_t), itemSize, top, space)))
|
||||
if (rcUnlikely(!align(sizeof(std::size_t), itemSize, top, space)))
|
||||
return nullptr;
|
||||
setTempPtrBufferType(top, BufferType_temp);
|
||||
setTempPtrPrev(top, mPrev);
|
||||
|
|
Loading…
Reference in a new issue