[Libreoffice-commits] core.git: Branch 'libreoffice-4-1' - sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Mon Aug 5 08:38:59 PDT 2013


 sc/source/filter/xml/xmlcelli.cxx |   42 ++++++++++++++++++++++++++++++--------
 sc/source/filter/xml/xmlcelli.hxx |    4 +++
 2 files changed, 38 insertions(+), 8 deletions(-)

New commits:
commit ec949345c018c97153be17b1d8a48be0ce3a1ff0
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Aug 2 02:00:27 2013 -0400

    fdo#67099: Don't use edit engine for a single unformatted paragraph.
    
    which is most common, and using edit engine for it would decrease
    loading performance.
    
    Change-Id: I65c20eef96c88edd8eb07c73c27716c4f03c4cda
    Reviewed-on: https://gerrit.libreoffice.org/5259
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 73d5f7e..470a3f4 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -158,10 +158,10 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
     bFormulaTextResult(false),
     mbPossibleErrorCell(false),
     mbCheckWithCompilerForError(false),
-    mbEditEngineHasText(false)
+    mbEditEngineHasText(false),
+    mbHasFormatRuns(false)
 {
     rtl::math::setNan(&fValue); // NaN by default
-    mpEditEngine->Clear();
 
     rXMLImport.SetRemoveLastChar(false);
     rXMLImport.GetTables().AddColumn(bTempIsCovered);
@@ -354,6 +354,7 @@ void ScXMLTableRowCellContext::PushParagraphSpan(const OUString& rSpan, const OU
 
 void ScXMLTableRowCellContext::PushParagraphField(SvxFieldData* pData, const OUString& rStyleName)
 {
+    mbHasFormatRuns = true;
     maFields.push_back(new Field(pData));
     Field& rField = maFields.back();
 
@@ -396,6 +397,7 @@ void ScXMLTableRowCellContext::PushFormat(sal_Int32 nBegin, sal_Int32 nEnd, cons
 
     const ScXMLEditAttributeMap& rEditAttrMap = GetScImport().GetEditAttributeMap();
 
+    mbHasFormatRuns = true;
     maFormats.push_back(new ParaFormat(*mpEditEngine));
     ParaFormat& rFmt = maFormats.back();
     rFmt.maSelection.nStartPara = rFmt.maSelection.nEndPara = mnCurParagraph;
@@ -591,6 +593,14 @@ void ScXMLTableRowCellContext::PushFormat(sal_Int32 nBegin, sal_Int32 nEnd, cons
         rFmt.maItemSet.Put(*pPoolItem);
 }
 
+OUString ScXMLTableRowCellContext::GetFirstParagraph() const
+{
+    if (maFirstParagraph.isEmpty())
+        return mpEditEngine->GetText(0);
+
+    return maFirstParagraph;
+}
+
 void ScXMLTableRowCellContext::PushParagraphFieldDate(const OUString& rStyleName)
 {
     PushParagraphField(new SvxDateField, rStyleName);
@@ -619,12 +629,27 @@ void ScXMLTableRowCellContext::PushParagraphEnd()
     // EditEngine always has at least one paragraph even when its content is empty.
 
     if (mbEditEngineHasText)
+    {
+        if (!maFirstParagraph.isEmpty())
+        {
+            // Flush the cached first paragraph first.
+            mpEditEngine->Clear();
+            mpEditEngine->SetText(maFirstParagraph);
+            maFirstParagraph = OUString();
+        }
         mpEditEngine->InsertParagraph(mpEditEngine->GetParagraphCount(), maParagraph.makeStringAndClear());
-    else
+    }
+    else if (mbHasFormatRuns)
     {
+        mpEditEngine->Clear();
         mpEditEngine->SetText(maParagraph.makeStringAndClear());
         mbEditEngineHasText = true;
     }
+    else if (mnCurParagraph == 0)
+    {
+        maFirstParagraph = maParagraph.makeStringAndClear();
+        mbEditEngineHasText = true;
+    }
 
     ++mnCurParagraph;
 }
@@ -1018,7 +1043,7 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
             if (maStringValue)
                 aCellString = *maStringValue;
             else if (mbEditEngineHasText)
-                aCellString = mpEditEngine->GetText(0);
+                aCellString = GetFirstParagraph();
             else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() )
                 aCellString = *pOUText;
             else
@@ -1059,10 +1084,10 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
         }
         else if (mbEditEngineHasText)
         {
-            if (maFields.empty() && maFormats.empty() && mpEditEngine->GetParagraphCount() == 1)
+            if (!maFirstParagraph.isEmpty())
             {
                 // This is a normal text without format runs.
-                rDoc.setStringCell(rCurrentPos, mpEditEngine->GetText());
+                rDoc.setStringCell(rCurrentPos, maFirstParagraph);
             }
             else
             {
@@ -1441,7 +1466,8 @@ void ScXMLTableRowCellContext::HasSpecialCaseFormulaText()
     if (!mbEditEngineHasText || mbNewValueType)
         return;
 
-    OUString aStr = mpEditEngine->GetText(0);
+    OUString aStr = GetFirstParagraph();
+
     if (aStr.isEmpty() || aStr.startsWith("Err:"))
         mbPossibleErrorCell = true;
     else if (aStr.startsWith("#"))
@@ -1463,7 +1489,7 @@ void ScXMLTableRowCellContext::EndElement()
     HasSpecialCaseFormulaText();
     if( bFormulaTextResult && (mbPossibleErrorCell || mbCheckWithCompilerForError) )
     {
-        maStringValue.reset(mpEditEngine->GetText(0));
+        maStringValue.reset(GetFirstParagraph());
         nCellType = util::NumberFormat::TEXT;
     }
 
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 45017c4..e49e3a3 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -65,6 +65,7 @@ class ScXMLTableRowCellContext : public ScXMLImportContext
     boost::optional<OUString> maContentValidationName;
 
     ScEditEngineDefaulter* mpEditEngine;
+    OUString maFirstParagraph; /// unformatted first paragraph, for better performance.
     OUStringBuffer maParagraph;
     sal_Int32 mnCurParagraph;
 
@@ -92,6 +93,7 @@ class ScXMLTableRowCellContext : public ScXMLImportContext
     bool mbPossibleErrorCell;
     bool mbCheckWithCompilerForError;
     bool mbEditEngineHasText;
+    bool mbHasFormatRuns;
 
     sal_Int16 GetCellType(const OUString& sOUValue) const;
 
@@ -124,6 +126,8 @@ class ScXMLTableRowCellContext : public ScXMLImportContext
 
     void PushFormat(sal_Int32 nBegin, sal_Int32 nEnd, const OUString& rStyleName);
 
+    OUString GetFirstParagraph() const;
+
 public:
 
     ScXMLTableRowCellContext( ScXMLImport& rImport, sal_uInt16 nPrfx,


More information about the Libreoffice-commits mailing list