Don't use alloca in inlined functions inside a loop.

This commit is contained in:
Bartosz Taudul 2020-05-24 16:17:54 +02:00
parent 2b304581cf
commit 7ceb4005cd
2 changed files with 22 additions and 4 deletions

View File

@ -2122,6 +2122,7 @@ Worker::~Worker()
LZ4_freeStreamDecode( (LZ4_streamDecode_t*)m_stream ); LZ4_freeStreamDecode( (LZ4_streamDecode_t*)m_stream );
delete[] m_frameImageBuffer; delete[] m_frameImageBuffer;
delete[] m_tmpBuf;
for( auto& v : m_data.threads ) for( auto& v : m_data.threads )
{ {
@ -4733,11 +4734,18 @@ void Worker::ProcessZoneText( const QueueZoneText& ev )
const auto str1 = it->second.ptr; const auto str1 = it->second.ptr;
const auto len0 = strlen( str0 ); const auto len0 = strlen( str0 );
const auto len1 = strlen( str1 ); const auto len1 = strlen( str1 );
char* buf = (char*)alloca( len0+len1+1 ); const auto bsz = len0+len1+1;
if( m_tmpBufSize < bsz )
{
delete[] m_tmpBuf;
m_tmpBuf = new char[bsz];
m_tmpBufSize = bsz;
}
char* buf = m_tmpBuf;
memcpy( buf, str0, len0 ); memcpy( buf, str0, len0 );
buf[len0] = '\n'; buf[len0] = '\n';
memcpy( buf+len0+1, str1, len1 ); memcpy( buf+len0+1, str1, len1 );
extra.text = StringIdx( StoreString( buf, len0+len1+1 ).idx ); extra.text = StringIdx( StoreString( buf, bsz ).idx );
} }
m_pendingCustomStrings.erase( it ); m_pendingCustomStrings.erase( it );
} }
@ -4785,11 +4793,18 @@ void Worker::ProcessZoneValue( const QueueZoneValue& ev )
{ {
const auto str0 = GetString( extra.text ); const auto str0 = GetString( extra.text );
const auto len0 = strlen( str0 ); const auto len0 = strlen( str0 );
char* buf = (char*)alloca( len0+tsz+1 ); const auto bsz = len0+tsz+1;
if( m_tmpBufSize < bsz )
{
delete[] m_tmpBuf;
m_tmpBuf = new char[bsz];
m_tmpBufSize = bsz;
}
char* buf = m_tmpBuf;
memcpy( buf, str0, len0 ); memcpy( buf, str0, len0 );
buf[len0] = '\n'; buf[len0] = '\n';
memcpy( buf+len0+1, tmp, tsz ); memcpy( buf+len0+1, tmp, tsz );
extra.text = StringIdx( StoreString( buf, len0+tsz+1 ).idx ); extra.text = StringIdx( StoreString( buf, bsz ).idx );
} }
} }

View File

@ -884,6 +884,9 @@ private:
#endif #endif
Vector<Parameter> m_params; Vector<Parameter> m_params;
char* m_tmpBuf = nullptr;
size_t m_tmpBufSize = 0;
}; };
} }