[Libreoffice-commits] core.git: formula/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Oct 10 10:58:53 UTC 2018


 formula/source/core/api/token.cxx |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

New commits:
commit 7600c63424db644065d736158c182cb9498574e9
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Tue Sep 18 15:00:38 2018 +0200
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Wed Oct 10 12:58:30 2018 +0200

    avoid usually needless large allocation for formula token array
    
    Change-Id: I855af060e1aeb91bccfc923ca567ad34d64be757
    Reviewed-on: https://gerrit.libreoffice.org/60861
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index 58fa8b77ece9..aa3e576a9323 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -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);


More information about the Libreoffice-commits mailing list