1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 04:23:51 +00:00

Deduplicate code.

This commit is contained in:
Bartosz Taudul 2020-02-23 19:16:33 +01:00
parent adbde78a7a
commit 085e1fd43f

View File

@ -34,10 +34,7 @@ public:
tracy_force_inline void* AllocRaw( size_t size ) tracy_force_inline void* AllocRaw( size_t size )
{ {
assert( size <= BlockSize ); assert( size <= BlockSize );
if( m_offset + size > BlockSize ) if( m_offset + size > BlockSize ) DoAlloc();
{
DoAlloc();
}
void* ret = m_ptr + m_offset; void* ret = m_ptr + m_offset;
m_offset += size; m_offset += size;
return ret; return ret;
@ -47,14 +44,8 @@ public:
tracy_force_inline T* AllocInit() tracy_force_inline T* AllocInit()
{ {
const auto size = sizeof( T ); const auto size = sizeof( T );
assert( size <= BlockSize ); auto ret = AllocRaw( size );
if( m_offset + size > BlockSize )
{
DoAlloc();
}
void* ret = m_ptr + m_offset;
new( ret ) T; new( ret ) T;
m_offset += size;
return (T*)ret; return (T*)ret;
} }
@ -62,19 +53,13 @@ public:
tracy_force_inline T* AllocInit( size_t sz ) tracy_force_inline T* AllocInit( size_t sz )
{ {
const auto size = sizeof( T ) * sz; const auto size = sizeof( T ) * sz;
assert( size <= BlockSize ); auto ret = AllocRaw( size );
if( m_offset + size > BlockSize )
{
DoAlloc();
}
void* ret = m_ptr + m_offset;
T* ptr = (T*)ret; T* ptr = (T*)ret;
for( size_t i=0; i<sz; i++ ) for( size_t i=0; i<sz; i++ )
{ {
new( ptr ) T; new( ptr ) T;
ptr++; ptr++;
} }
m_offset += size;
return (T*)ret; return (T*)ret;
} }