[Libreoffice-commits] core.git: sc/inc sc/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Sun May 2 10:00:31 UTC 2021


 sc/inc/documentimport.hxx              |    5 +++++
 sc/source/core/data/documentimport.cxx |   21 +++++++++++++++++++++
 sc/source/filter/oox/stylesbuffer.cxx  |    7 ++++---
 3 files changed, 30 insertions(+), 3 deletions(-)

New commits:
commit ffde7949ab6bd434b0f086d1a3bdf83f31aeda48
Author:     Noel Grandin <noel at peralex.com>
AuthorDate: Sat May 1 11:42:03 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun May 2 11:59:53 2021 +0200

    tdf#79049 speed up OOXML workbook load (5)
    
    Sc::NumUtil::isLatinScript is pretty hot, so add a small
    cache to ScDocumentImport.
    
    This takes my load time from 27s to 18s.
    
    Change-Id: I51fa891836d678f0d8700653e3a3a095297aeae7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114987
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/inc/documentimport.hxx b/sc/inc/documentimport.hxx
index 8dcb3726bde3..cefe2949dcc7 100644
--- a/sc/inc/documentimport.hxx
+++ b/sc/inc/documentimport.hxx
@@ -21,6 +21,7 @@
 class EditTextObject;
 class ScDocument;
 class ScColumn;
+class ScPatternAttr;
 class ScTokenArray;
 class ScFormulaCell;
 class ScStyleSheet;
@@ -132,6 +133,10 @@ public:
      */
     void broadcastRecalcAfterImport();
 
+    /** small cache for hot call during import */
+    bool isLatinScript(sal_uInt32 nFormat);
+    bool isLatinScript(const ScPatternAttr&);
+
 private:
     void initColumn(ScColumn& rCol);
     static void broadcastRecalcAfterImportColumn(ScColumn& rCol);
diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx
index f4cb0e24c0c0..2dbc61c03938 100644
--- a/sc/source/core/data/documentimport.cxx
+++ b/sc/source/core/data/documentimport.cxx
@@ -23,11 +23,13 @@
 #include <sharedformula.hxx>
 #include <bcaslot.hxx>
 #include <scopetools.hxx>
+#include <numformat.hxx>
 
 #include <o3tl/safeint.hxx>
 #include <svl/sharedstringpool.hxx>
 #include <svl/languageoptions.hxx>
 #include <unotools/configmgr.hxx>
+#include <unordered_map>
 
 namespace {
 
@@ -52,6 +54,7 @@ struct ScDocumentImportImpl
     std::vector<sc::TableColumnBlockPositionSet> maBlockPosSet;
     SvtScriptType mnDefaultScriptNumeric;
     std::vector<TabAttr> maTabAttrs;
+    std::unordered_map<sal_uInt32, bool> maIsLatinScriptMap;
 
     explicit ScDocumentImportImpl(ScDocument& rDoc) :
         mrDoc(rDoc),
@@ -808,4 +811,22 @@ void ScDocumentImport::broadcastRecalcAfterImportColumn(ScColumn& rCol)
     std::for_each(rCol.maCells.begin(), rCol.maCells.end(), aFunc);
 }
 
+
+bool ScDocumentImport::isLatinScript(const ScPatternAttr& rPatAttr)
+{
+    SvNumberFormatter* pFormatter = mpImpl->mrDoc.GetFormatTable();
+    sal_uInt32 nKey = rPatAttr.GetNumberFormat(pFormatter);
+    return isLatinScript(nKey);
+}
+
+bool ScDocumentImport::isLatinScript(sal_uInt32 nFormat)
+{
+    auto it = mpImpl->maIsLatinScriptMap.find(nFormat);
+    if (it != mpImpl->maIsLatinScriptMap.end())
+        return it->second;
+    bool b = sc::NumFmtUtil::isLatinScript(nFormat, mpImpl->mrDoc);
+    mpImpl->maIsLatinScriptMap.emplace(nFormat, b);
+    return b;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx
index 7834d5e5a058..e91cb7e47ba5 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -2028,6 +2028,7 @@ void Xf::applyPatternToAttrList( AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal
 {
     createPattern();
     ScPatternAttr& rPat = *mpPattern;
+    ScDocumentImport& rDocImport = getDocImport();
     ScDocument& rDoc = getScDocument();
     if ( isCellXf() )
     {
@@ -2061,7 +2062,7 @@ void Xf::applyPatternToAttrList( AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal
         rPat.GetItemSet().Put(aNumPat.GetItemSet());
     }
 
-    if (!sc::NumFmtUtil::isLatinScript(mnScNumFmt, rDoc))
+    if (!rDocImport.isLatinScript(mnScNumFmt))
         rAttrs.mbLatinNumFmtOnly = false;
 
     if (!rPat.GetStyleName())
@@ -2085,7 +2086,7 @@ void Xf::applyPatternToAttrList( AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal
         rAttrs.maAttrs.push_back(aEntry);
 
         // Check if the default pattern is 'General'.
-        if (!sc::NumFmtUtil::isLatinScript(*aEntry.pPattern, rDoc))
+        if (!rDocImport.isLatinScript(*aEntry.pPattern))
             rAttrs.mbLatinNumFmtOnly = false;
     }
 
@@ -2094,7 +2095,7 @@ void Xf::applyPatternToAttrList( AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal
     aEntry.pPattern = &rDoc.GetPool()->Put(rPat);
     rAttrs.maAttrs.push_back(aEntry);
 
-    if (!sc::NumFmtUtil::isLatinScript(*aEntry.pPattern, rDoc))
+    if (!rDocImport.isLatinScript(*aEntry.pPattern))
         rAttrs.mbLatinNumFmtOnly = false;
 }
 


More information about the Libreoffice-commits mailing list