Kaydet (Commit) 7600c634 authored tarafından Luboš Luňák's avatar Luboš Luňák

avoid usually needless large allocation for formula token array

Change-Id: I855af060e1aeb91bccfc923ca567ad34d64be757
Reviewed-on: https://gerrit.libreoffice.org/60861
Tested-by: Jenkins
Reviewed-by: 's avatarLuboš Luňák <l.lunak@collabora.com>
üst b5680189
......@@ -776,8 +776,19 @@ FormulaToken* FormulaTokenArray::Add( FormulaToken* t )
return nullptr;
}
// Allocating an array of size FORMULA_MAXTOKENS is simple, but that results in relatively large
// allocations that malloc() implementations usually do not handle as efficiently as smaller
// sizes (not only in terms of memory usage but also speed). Since most token arrays are going
// to be small, start with a small array and resize only if needed.
const size_t MAX_FAST_TOKENS = 32;
if( !pCode )
pCode.reset(new FormulaToken*[ FORMULA_MAXTOKENS ]);
pCode.reset(new FormulaToken*[ MAX_FAST_TOKENS ]);
if( nLen == MAX_FAST_TOKENS )
{
FormulaToken** tmp = new FormulaToken*[ FORMULA_MAXTOKENS ];
std::copy(&pCode[0], &pCode[MAX_FAST_TOKENS], tmp);
pCode.reset(tmp);
}
if( nLen < FORMULA_MAXTOKENS - 1 )
{
CheckToken(*t);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment