mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 17:39:42 +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;
|
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
|
#endif
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace DetourNavigator
|
||||||
std::size_t space = mStack.size() - getUsedSize();
|
std::size_t space = mStack.size() - getUsedSize();
|
||||||
void* top = mTop;
|
void* top = mTop;
|
||||||
const auto itemSize = 2 * sizeof(std::size_t) + size;
|
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;
|
return nullptr;
|
||||||
setTempPtrBufferType(top, BufferType_temp);
|
setTempPtrBufferType(top, BufferType_temp);
|
||||||
setTempPtrPrev(top, mPrev);
|
setTempPtrPrev(top, mPrev);
|
||||||
|
|
Loading…
Reference in a new issue