[Libreoffice-commits] .: 5 commits - sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Thu Dec 2 13:08:18 PST 2010


 sc/source/filter/xml/XMLStylesExportHelper.cxx |   60 +++++++++-------
 sc/source/filter/xml/XMLStylesExportHelper.hxx |   19 ++++-
 sc/source/filter/xml/cachedattraccess.cxx      |   70 +++++++++++++++++++
 sc/source/filter/xml/cachedattraccess.hxx      |   63 +++++++++++++++++
 sc/source/filter/xml/makefile.mk               |    1 
 sc/source/filter/xml/xmlexprt.cxx              |   92 ++++++++++++++-----------
 sc/source/filter/xml/xmlexprt.hxx              |   12 +--
 7 files changed, 246 insertions(+), 71 deletions(-)

New commits:
commit ce1bb2d741b913c372755778e12b682b3b21c469
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Thu Dec 2 11:25:54 2010 -0500

    Moved new wrapper class into own files.

diff --git a/sc/source/filter/xml/cachedattraccess.cxx b/sc/source/filter/xml/cachedattraccess.cxx
new file mode 100644
index 0000000..b5ef932
--- /dev/null
+++ b/sc/source/filter/xml/cachedattraccess.cxx
@@ -0,0 +1,70 @@
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ *       [ Kohei Yoshida <kyoshida at novell.com> ]
+ * Portions created by the Initial Developer are Copyright (C) 2010 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sc.hxx"
+
+#include "cachedattraccess.hxx"
+#include "document.hxx"
+
+ScXMLCachedRowAttrAccess::Cache::Cache() :
+    mnTab(-1), mnRow1(-1), mnRow2(-1), mbValue(false) {}
+
+bool ScXMLCachedRowAttrAccess::Cache::hasCache(sal_Int32 nTab, sal_Int32 nRow) const
+{
+    return mnTab == nTab && mnRow1 <= nRow && nRow <= mnRow2;
+}
+
+ScXMLCachedRowAttrAccess::ScXMLCachedRowAttrAccess(ScDocument* pDoc) :
+    mpDoc(pDoc) {}
+
+bool ScXMLCachedRowAttrAccess::rowHidden(sal_Int32 nTab, sal_Int32 nRow)
+{
+    if (!maHidden.hasCache(nTab, nRow))
+    {
+        SCROW nRow1, nRow2;
+        maHidden.mbValue = mpDoc->RowHidden(
+            static_cast<SCTAB>(nTab), static_cast<SCROW>(nRow), &nRow1, &nRow2);
+        maHidden.mnRow1 = static_cast<sal_Int32>(nRow1);
+        maHidden.mnRow2 = static_cast<sal_Int32>(nRow2);
+    }
+    return maHidden.mbValue;
+}
+
+bool ScXMLCachedRowAttrAccess::rowFiltered(sal_Int32 nTab, sal_Int32 nRow)
+{
+    if (!maFiltered.hasCache(nTab, nRow))
+    {
+        SCROW nRow1, nRow2;
+        maFiltered.mbValue = mpDoc->RowFiltered(
+            static_cast<SCTAB>(nTab), static_cast<SCROW>(nRow), &nRow1, &nRow2);
+        maFiltered.mnRow1 = static_cast<sal_Int32>(nRow1);
+        maFiltered.mnRow2 = static_cast<sal_Int32>(nRow2);
+    }
+    return maFiltered.mbValue;
+}
+
diff --git a/sc/source/filter/xml/cachedattraccess.hxx b/sc/source/filter/xml/cachedattraccess.hxx
new file mode 100644
index 0000000..5ef6e41
--- /dev/null
+++ b/sc/source/filter/xml/cachedattraccess.hxx
@@ -0,0 +1,63 @@
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ *       [ Kohei Yoshida <kyoshida at novell.com> ]
+ * Portions created by the Initial Developer are Copyright (C) 2010 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#ifndef __SC_FILTER_XML_CACHEDATTRACCESS_HXX__
+#define __SC_FILTER_XML_CACHEDATTRACCESS_HXX__
+
+#include "sal/types.h"
+
+class ScDocument;
+
+/**
+ * Wrapper for accessing hidden and filtered row attributes.  It caches last
+ * accessed values for a current range, to avoid fetching values for every
+ * single row.
+ */
+class ScXMLCachedRowAttrAccess
+{
+    struct Cache
+    {
+        sal_Int32   mnTab;
+        sal_Int32   mnRow1;
+        sal_Int32   mnRow2;
+        bool        mbValue;
+        Cache();
+        bool hasCache(sal_Int32 nTab, sal_Int32 nRow) const;
+    };
+
+public:
+    ScXMLCachedRowAttrAccess(ScDocument* pDoc);
+
+    bool rowHidden(sal_Int32 nTab, sal_Int32 nRow);
+    bool rowFiltered(sal_Int32 nTab, sal_Int32 nRow);
+private:
+    Cache maHidden;
+    Cache maFiltered;
+    ScDocument* mpDoc;
+};
+
+#endif
diff --git a/sc/source/filter/xml/makefile.mk b/sc/source/filter/xml/makefile.mk
index 47d4281..777d68c 100644
--- a/sc/source/filter/xml/makefile.mk
+++ b/sc/source/filter/xml/makefile.mk
@@ -47,6 +47,7 @@ PROJECTPCHSOURCE=..\pch\filt_pch
 
 SLOFILES =  \
         $(SLO)$/sheetdata.obj \
+        $(SLO)$/cachedattraccess.obj \
         $(SLO)$/xmlwrap.obj \
         $(SLO)$/xmlimprt.obj \
         $(SLO)$/xmlexprt.obj \
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 2fdb017..1c62691 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -69,6 +69,7 @@
 #include "externalrefmgr.hxx"
 #include "editutil.hxx"
 #include "tabprotection.hxx"
+#include "cachedattraccess.hxx"
 
 #include <xmloff/xmltoken.hxx>
 #include <xmloff/xmlnmspe.hxx>
@@ -170,43 +171,6 @@ using ::rtl::OUStringBuffer;
 using ::com::sun::star::uno::Reference;
 using ::com::sun::star::uno::UNO_QUERY;
 
-ScXMLRowAttrAccess::Cache::Cache() :
-    mnTab(-1), mnRow1(-1), mnRow2(-1), mbValue(false) {}
-
-bool ScXMLRowAttrAccess::Cache::hasCache(sal_Int32 nTab, sal_Int32 nRow) const
-{
-    return mnTab == nTab && mnRow1 <= nRow && nRow <= mnRow2;
-}
-
-ScXMLRowAttrAccess::ScXMLRowAttrAccess(ScDocument* pDoc) :
-    mpDoc(pDoc) {}
-
-bool ScXMLRowAttrAccess::rowHidden(sal_Int32 nTab, sal_Int32 nRow)
-{
-    if (!maHidden.hasCache(nTab, nRow))
-    {
-        SCROW nRow1, nRow2;
-        maHidden.mbValue = mpDoc->RowHidden(
-            static_cast<SCTAB>(nTab), static_cast<SCROW>(nRow), &nRow1, &nRow2);
-        maHidden.mnRow1 = static_cast<sal_Int32>(nRow1);
-        maHidden.mnRow2 = static_cast<sal_Int32>(nRow2);
-    }
-    return maHidden.mbValue;
-}
-
-bool ScXMLRowAttrAccess::rowFiltered(sal_Int32 nTab, sal_Int32 nRow)
-{
-    if (!maFiltered.hasCache(nTab, nRow))
-    {
-        SCROW nRow1, nRow2;
-        maFiltered.mbValue = mpDoc->RowFiltered(
-            static_cast<SCTAB>(nTab), static_cast<SCROW>(nRow), &nRow1, &nRow2);
-        maFiltered.mnRow1 = static_cast<sal_Int32>(nRow1);
-        maFiltered.mnRow2 = static_cast<sal_Int32>(nRow2);
-    }
-    return maFiltered.mbValue;
-}
-
 //----------------------------------------------------------------------------
 
 namespace
@@ -1340,7 +1304,7 @@ void ScXMLExport::OpenAndCloseRow(
     pRowFormatRanges->Clear();
 }
 
-void ScXMLExport::OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, const sal_Int32 nRepeatRow, ScXMLRowAttrAccess& rRowAttr)
+void ScXMLExport::OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, const sal_Int32 nRepeatRow, ScXMLCachedRowAttrAccess& rRowAttr)
 {
     if (nRepeatRow > 1)
     {
@@ -1437,7 +1401,7 @@ void ScXMLExport::ExportFormatRanges(const sal_Int32 nStartCol, const sal_Int32
     const sal_Int32 nEndCol, const sal_Int32 nEndRow, const sal_Int32 nSheet)
 {
     pRowFormatRanges->Clear();
-    ScXMLRowAttrAccess aRowAttr(pDoc);
+    ScXMLCachedRowAttrAccess aRowAttr(pDoc);
     if (nStartRow == nEndRow)
     {
         pCellStyles->GetFormatRanges(nStartCol, nEndCol, nStartRow, nSheet, pRowFormatRanges);
diff --git a/sc/source/filter/xml/xmlexprt.hxx b/sc/source/filter/xml/xmlexprt.hxx
index 5db9bc4..b77a40a 100644
--- a/sc/source/filter/xml/xmlexprt.hxx
+++ b/sc/source/filter/xml/xmlexprt.hxx
@@ -65,32 +65,10 @@ class ScChartListener;
 class SfxItemPool;
 class ScAddress;
 class ScBaseCell;
+class ScXMLCachedRowAttrAccess;
 
 typedef std::vector< com::sun::star::uno::Reference < com::sun::star::drawing::XShapes > > ScMyXShapesVec;
 
-class ScXMLRowAttrAccess
-{
-    struct Cache
-    {
-        sal_Int32   mnTab;
-        sal_Int32   mnRow1;
-        sal_Int32   mnRow2;
-        bool    mbValue;
-        Cache();
-        bool hasCache(sal_Int32 nTab, sal_Int32 nRow) const;
-    };
-
-public:
-    ScXMLRowAttrAccess(ScDocument* pDoc);
-
-    bool rowHidden(sal_Int32 nTab, sal_Int32 nRow);
-    bool rowFiltered(sal_Int32 nTab, sal_Int32 nRow);
-private:
-    Cache maHidden;
-    Cache maFiltered;
-    ScDocument* mpDoc;
-};
-
 class ScXMLExport : public SvXMLExport
 {
     ScDocument*					pDoc;
@@ -190,7 +168,7 @@ class ScXMLExport : public SvXMLExport
                     bool bHidden, bool bFiltered);
     void OpenAndCloseRow(const sal_Int32 nIndex, const sal_Int32 nStartRow, const sal_Int32 nEmptyRows, 
                          bool bHidden, bool bFiltered);
-    void OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, const sal_Int32 nRepeatRow, ScXMLRowAttrAccess& rRowAttr);
+    void OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, const sal_Int32 nRepeatRow, ScXMLCachedRowAttrAccess& rRowAttr);
     void CloseRow(const sal_Int32 nRow);
     void GetColumnRowHeader(sal_Bool& bHasColumnHeader, com::sun::star::table::CellRangeAddress& aColumnHeaderRange,
         sal_Bool& bHasRowHeader, com::sun::star::table::CellRangeAddress& aRowHeaderRange,
commit fe1a7205afe9cf1f19f50937864a4be5c456ccef
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Dec 1 19:27:25 2010 -0500

    Refactored to avoid using CR_HIDDEN and CR_FILTERED.
    
    CR_HIDDEN and CR_FILTERED as row attributes are deprecated; we
    should eliminate all instances of their usage ASAP.

diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 613fa45..2fdb017 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -170,6 +170,43 @@ using ::rtl::OUStringBuffer;
 using ::com::sun::star::uno::Reference;
 using ::com::sun::star::uno::UNO_QUERY;
 
+ScXMLRowAttrAccess::Cache::Cache() :
+    mnTab(-1), mnRow1(-1), mnRow2(-1), mbValue(false) {}
+
+bool ScXMLRowAttrAccess::Cache::hasCache(sal_Int32 nTab, sal_Int32 nRow) const
+{
+    return mnTab == nTab && mnRow1 <= nRow && nRow <= mnRow2;
+}
+
+ScXMLRowAttrAccess::ScXMLRowAttrAccess(ScDocument* pDoc) :
+    mpDoc(pDoc) {}
+
+bool ScXMLRowAttrAccess::rowHidden(sal_Int32 nTab, sal_Int32 nRow)
+{
+    if (!maHidden.hasCache(nTab, nRow))
+    {
+        SCROW nRow1, nRow2;
+        maHidden.mbValue = mpDoc->RowHidden(
+            static_cast<SCTAB>(nTab), static_cast<SCROW>(nRow), &nRow1, &nRow2);
+        maHidden.mnRow1 = static_cast<sal_Int32>(nRow1);
+        maHidden.mnRow2 = static_cast<sal_Int32>(nRow2);
+    }
+    return maHidden.mbValue;
+}
+
+bool ScXMLRowAttrAccess::rowFiltered(sal_Int32 nTab, sal_Int32 nRow)
+{
+    if (!maFiltered.hasCache(nTab, nRow))
+    {
+        SCROW nRow1, nRow2;
+        maFiltered.mbValue = mpDoc->RowFiltered(
+            static_cast<SCTAB>(nTab), static_cast<SCROW>(nRow), &nRow1, &nRow2);
+        maFiltered.mnRow1 = static_cast<sal_Int32>(nRow1);
+        maFiltered.mnRow2 = static_cast<sal_Int32>(nRow2);
+    }
+    return maFiltered.mbValue;
+}
+
 //----------------------------------------------------------------------------
 
 namespace
@@ -1213,18 +1250,18 @@ void ScXMLExport::WriteRowContent()
     }
 }
 
-void ScXMLExport::WriteRowStartTag(sal_Int32 nRow, const sal_Int32 nIndex,
-    const sal_Int8 nFlag, const sal_Int32 nEqualRows)
+void ScXMLExport::WriteRowStartTag(
+    sal_Int32 nRow, const sal_Int32 nIndex, const sal_Int32 nEqualRows,
+    bool bHidden, bool bFiltered)
 {
     AddAttribute(sAttrStyleName, *pRowStyles->GetStyleNameByIndex(nIndex));
-    if (nFlag)
-        if (nFlag & CR_HIDDEN)
-        {
-            if (nFlag & CR_FILTERED)
-                AddAttribute(XML_NAMESPACE_TABLE, XML_VISIBILITY, XML_FILTER);
-            else
-                AddAttribute(XML_NAMESPACE_TABLE, XML_VISIBILITY, XML_COLLAPSE);
-        }
+    if (bHidden)
+    {
+        if (bFiltered)
+            AddAttribute(XML_NAMESPACE_TABLE, XML_VISIBILITY, XML_FILTER);
+        else
+            AddAttribute(XML_NAMESPACE_TABLE, XML_VISIBILITY, XML_COLLAPSE);
+    }
     if (nEqualRows > 1)
     {
         rtl::OUStringBuffer aBuf;
@@ -1258,7 +1295,9 @@ void ScXMLExport::CloseHeaderRows()
     EndElement(XML_NAMESPACE_TABLE, XML_TABLE_HEADER_ROWS, sal_True);
 }
 
-void ScXMLExport::OpenNewRow(const sal_Int32 nIndex, const sal_Int8 nFlag, const sal_Int32 nStartRow, const sal_Int32 nEqualRows)
+void ScXMLExport::OpenNewRow(
+    const sal_Int32 nIndex, const sal_Int32 nStartRow, const sal_Int32 nEqualRows,
+    bool bHidden, bool bFiltered)
 {
     nOpenRow = nStartRow;
     if (pGroupRows->IsGroupStart(nStartRow))
@@ -1278,35 +1317,38 @@ void ScXMLExport::OpenNewRow(const sal_Int32 nIndex, const sal_Int8 nFlag, const
             nEquals = aRowHeaderRange.EndRow - nStartRow + 1;
         else
             nEquals = nEqualRows;
-        WriteRowStartTag(nStartRow, nIndex, nFlag, nEquals);
+        WriteRowStartTag(nStartRow, nIndex, nEquals, bHidden, bFiltered);
         nOpenRow = nStartRow + nEquals - 1;
         if (nEquals < nEqualRows)
         {
             CloseRow(nStartRow + nEquals - 1);
-            WriteRowStartTag(nStartRow, nIndex, nFlag, nEqualRows - nEquals);
+            WriteRowStartTag(nStartRow, nIndex, nEqualRows - nEquals, bHidden, bFiltered);
             nOpenRow = nStartRow + nEqualRows - 1;
         }
     }
     else
-        WriteRowStartTag(nStartRow, nIndex, nFlag, nEqualRows);
+        WriteRowStartTag(nStartRow, nIndex, nEqualRows, bHidden, bFiltered);
 }
 
-void ScXMLExport::OpenAndCloseRow(const sal_Int32 nIndex, const sal_Int8 nFlag,
-    const sal_Int32 nStartRow, const sal_Int32 nEqualRows)
+void ScXMLExport::OpenAndCloseRow(
+    const sal_Int32 nIndex, const sal_Int32 nStartRow, const sal_Int32 nEqualRows,
+    bool bHidden, bool bFiltered)
 {
-    OpenNewRow(nIndex, nFlag, nStartRow, nEqualRows);
+    OpenNewRow(nIndex, nStartRow, nEqualRows, bHidden, bFiltered);
     WriteRowContent();
     CloseRow(nStartRow + nEqualRows - 1);
     pRowFormatRanges->Clear();
 }
 
-void ScXMLExport::OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, const sal_Int32 nRepeatRow)
+void ScXMLExport::OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, const sal_Int32 nRepeatRow, ScXMLRowAttrAccess& rRowAttr)
 {
     if (nRepeatRow > 1)
     {
         sal_Int32 nPrevIndex(0), nIndex;
-        sal_Int8 nPrevFlag(0);
-        sal_Int8 nFlag(0);
+        bool bPrevHidden = false;
+        bool bPrevFiltered = false;
+        bool bHidden = false;
+        bool bFiltered = false;
         sal_Int32 nEqualRows(1);
         sal_Int32 nEndRow(nStartRow + nRepeatRow);
         sal_Int32 nRow;
@@ -1316,14 +1358,20 @@ void ScXMLExport::OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, con
             {
                 nPrevIndex = pRowStyles->GetStyleNameIndex(nTable, nRow);
                 if (pDoc)
-                    nPrevFlag = (pDoc->GetRowFlags(static_cast<SCROW>(nRow), static_cast<SCTAB>(nTable))) & (CR_HIDDEN | CR_FILTERED);
+                {
+                    bPrevHidden = rRowAttr.rowHidden(nTable, nRow);
+                    bPrevFiltered = rRowAttr.rowFiltered(nTable, nRow);
+                }
             }
             else
             {
                 nIndex = pRowStyles->GetStyleNameIndex(nTable, nRow);
                 if (pDoc)
-                    nFlag = (pDoc->GetRowFlags(static_cast<SCROW>(nRow), static_cast<SCTAB>(nTable))) & (CR_HIDDEN | CR_FILTERED);
-                if (nIndex == nPrevIndex && nFlag == nPrevFlag &&
+                {
+                    bHidden = rRowAttr.rowHidden(nTable, nRow);
+                    bFiltered = rRowAttr.rowFiltered(nTable, nRow);
+                }
+                if (nIndex == nPrevIndex && bHidden == bPrevHidden && bFiltered == bPrevFiltered &&
                     !(bHasRowHeader && ((nRow == aRowHeaderRange.StartRow) || (nRow - 1 == aRowHeaderRange.EndRow))) &&
                     !(pGroupRows->IsGroupStart(nRow)) &&
                     !(pGroupRows->IsGroupEnd(nRow - 1)))
@@ -1333,27 +1381,32 @@ void ScXMLExport::OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, con
                     if (nRow < nEndRow)
                     {
                         ScRowFormatRanges* pTempRowFormatRanges = new ScRowFormatRanges(pRowFormatRanges);
-                        OpenAndCloseRow(nPrevIndex, nPrevFlag, nRow - nEqualRows, nEqualRows);
+                        OpenAndCloseRow(nPrevIndex, nRow - nEqualRows, nEqualRows, bPrevHidden, bPrevFiltered);
                         delete pRowFormatRanges;
                         pRowFormatRanges = pTempRowFormatRanges;
                     }
                     else
-                        OpenAndCloseRow(nPrevIndex, nPrevFlag, nRow - nEqualRows, nEqualRows);
+                        OpenAndCloseRow(nPrevIndex, nRow - nEqualRows, nEqualRows, bPrevHidden, bPrevFiltered);
                     nEqualRows = 1;
                     nPrevIndex = nIndex;
-                    nPrevFlag = nFlag;
+                    bPrevHidden = bHidden;
+                    bPrevFiltered = bFiltered;
                 }
             }
         }
-        OpenNewRow(nPrevIndex, nPrevFlag, nRow - nEqualRows, nEqualRows);
+        OpenNewRow(nPrevIndex, nRow - nEqualRows, nEqualRows, bPrevHidden, bPrevFiltered);
     }
     else
     {
         sal_Int32 nIndex = pRowStyles->GetStyleNameIndex(nTable, nStartRow);
-        sal_Int8 nFlag(0);
+        bool bHidden = false;
+        bool bFiltered = false;
         if (pDoc)
-            nFlag = (pDoc->GetRowFlags(static_cast<SCROW>(nStartRow), static_cast<SCTAB>(nTable))) & (CR_HIDDEN | CR_FILTERED);
-        OpenNewRow(nIndex, nFlag, nStartRow, 1);
+        {
+            bHidden = rRowAttr.rowHidden(nTable, nStartRow);
+            bFiltered = rRowAttr.rowFiltered(nTable, nStartRow);
+        }
+        OpenNewRow(nIndex, nStartRow, 1, bHidden, bFiltered);
     }
     nOpenRow = nStartRow + nRepeatRow - 1;
 }
@@ -1384,11 +1437,12 @@ void ScXMLExport::ExportFormatRanges(const sal_Int32 nStartCol, const sal_Int32
     const sal_Int32 nEndCol, const sal_Int32 nEndRow, const sal_Int32 nSheet)
 {
     pRowFormatRanges->Clear();
+    ScXMLRowAttrAccess aRowAttr(pDoc);
     if (nStartRow == nEndRow)
     {
         pCellStyles->GetFormatRanges(nStartCol, nEndCol, nStartRow, nSheet, pRowFormatRanges);
         if (nOpenRow == - 1)
-            OpenRow(nSheet, nStartRow, 1);
+            OpenRow(nSheet, nStartRow, 1, aRowAttr);
         WriteRowContent();
         pRowFormatRanges->Clear();
     }
@@ -1409,12 +1463,12 @@ void ScXMLExport::ExportFormatRanges(const sal_Int32 nStartCol, const sal_Int32
                 DBG_ASSERT(nMaxRows, "something wents wrong");
                 if (nMaxRows >= nTotalRows - nRows)
                 {
-                    OpenRow(nSheet, nStartRow + nRows, nTotalRows - nRows);
+                    OpenRow(nSheet, nStartRow + nRows, nTotalRows - nRows, aRowAttr);
                     nRows += nTotalRows - nRows;
                 }
                 else
                 {
-                    OpenRow(nSheet, nStartRow + nRows, nMaxRows);
+                    OpenRow(nSheet, nStartRow + nRows, nMaxRows, aRowAttr);
                     nRows += nMaxRows;
                 }
                 if (!pRowFormatRanges->GetSize())
@@ -1424,7 +1478,7 @@ void ScXMLExport::ExportFormatRanges(const sal_Int32 nStartCol, const sal_Int32
             }
             if (nTotalRows == 1)
                 CloseRow(nStartRow);
-            OpenRow(nSheet, nEndRow, 1);
+            OpenRow(nSheet, nEndRow, 1, aRowAttr);
             pRowFormatRanges->Clear();
             pCellStyles->GetFormatRanges(0, nEndCol, nEndRow, nSheet, pRowFormatRanges);
             WriteRowContent();
@@ -1439,12 +1493,12 @@ void ScXMLExport::ExportFormatRanges(const sal_Int32 nStartCol, const sal_Int32
                 sal_Int32 nMaxRows = pRowFormatRanges->GetMaxRows();
                 if (nMaxRows >= nTotalRows - nRows)
                 {
-                    OpenRow(nSheet, nStartRow + nRows, nTotalRows - nRows);
+                    OpenRow(nSheet, nStartRow + nRows, nTotalRows - nRows, aRowAttr);
                     nRows += nTotalRows - nRows;
                 }
                 else
                 {
-                    OpenRow(nSheet, nStartRow + nRows, nMaxRows);
+                    OpenRow(nSheet, nStartRow + nRows, nMaxRows, aRowAttr);
                     nRows += nMaxRows;
                 }
                 if (!pRowFormatRanges->GetSize())
@@ -1452,7 +1506,7 @@ void ScXMLExport::ExportFormatRanges(const sal_Int32 nStartCol, const sal_Int32
                 WriteRowContent();
                 CloseRow(nStartRow + nRows - 1);
             }
-            OpenRow(nSheet, nEndRow, 1);
+            OpenRow(nSheet, nEndRow, 1, aRowAttr);
             pRowFormatRanges->Clear();
             pCellStyles->GetFormatRanges(0, nEndCol, nEndRow, nSheet, pRowFormatRanges);
             WriteRowContent();
diff --git a/sc/source/filter/xml/xmlexprt.hxx b/sc/source/filter/xml/xmlexprt.hxx
index e89deb8..5db9bc4 100644
--- a/sc/source/filter/xml/xmlexprt.hxx
+++ b/sc/source/filter/xml/xmlexprt.hxx
@@ -68,6 +68,29 @@ class ScBaseCell;
 
 typedef std::vector< com::sun::star::uno::Reference < com::sun::star::drawing::XShapes > > ScMyXShapesVec;
 
+class ScXMLRowAttrAccess
+{
+    struct Cache
+    {
+        sal_Int32   mnTab;
+        sal_Int32   mnRow1;
+        sal_Int32   mnRow2;
+        bool    mbValue;
+        Cache();
+        bool hasCache(sal_Int32 nTab, sal_Int32 nRow) const;
+    };
+
+public:
+    ScXMLRowAttrAccess(ScDocument* pDoc);
+
+    bool rowHidden(sal_Int32 nTab, sal_Int32 nRow);
+    bool rowFiltered(sal_Int32 nTab, sal_Int32 nRow);
+private:
+    Cache maHidden;
+    Cache maFiltered;
+    ScDocument* mpDoc;
+};
+
 class ScXMLExport : public SvXMLExport
 {
     ScDocument*					pDoc;
@@ -160,13 +183,14 @@ class ScXMLExport : public SvXMLExport
     void ExportFormatRanges(const sal_Int32 nStartCol, const sal_Int32 nStartRow,
         const sal_Int32 nEndCol, const sal_Int32 nEndRow, const sal_Int32 nSheet);
     void WriteRowContent();
-    void WriteRowStartTag(sal_Int32 nRow, const sal_Int32 nIndex, const sal_Int8 nFlag, const sal_Int32 nEmptyRows);
+    void WriteRowStartTag(sal_Int32 nRow, const sal_Int32 nIndex, const sal_Int32 nEmptyRows, bool bHidden, bool bFiltered);
     void OpenHeaderRows();
     void CloseHeaderRows();
-    void OpenNewRow(const sal_Int32 nIndex, const sal_Int8 nFlag, const sal_Int32 nStartRow, const sal_Int32 nEmptyRows);
-    void OpenAndCloseRow(const sal_Int32 nIndex, const sal_Int8 nFlag,
-        const sal_Int32 nStartRow, const sal_Int32 nEmptyRows);
-    void OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, const sal_Int32 nRepeatRow);
+    void OpenNewRow(const sal_Int32 nIndex, const sal_Int32 nStartRow, const sal_Int32 nEmptyRows,
+                    bool bHidden, bool bFiltered);
+    void OpenAndCloseRow(const sal_Int32 nIndex, const sal_Int32 nStartRow, const sal_Int32 nEmptyRows, 
+                         bool bHidden, bool bFiltered);
+    void OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, const sal_Int32 nRepeatRow, ScXMLRowAttrAccess& rRowAttr);
     void CloseRow(const sal_Int32 nRow);
     void GetColumnRowHeader(sal_Bool& bHasColumnHeader, com::sun::star::table::CellRangeAddress& aColumnHeaderRange,
         sal_Bool& bHasRowHeader, com::sun::star::table::CellRangeAddress& aRowHeaderRange,
commit 83ebe9699eb77cdd9cb61d43041435f364cb7be1
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Dec 1 01:25:06 2010 -0500

    Cache field style index for current range for better performance.
    
    This cuts about 3 seconds off with my test document.

diff --git a/sc/source/filter/xml/XMLStylesExportHelper.cxx b/sc/source/filter/xml/XMLStylesExportHelper.cxx
index c551fb4..5120ac2 100644
--- a/sc/source/filter/xml/XMLStylesExportHelper.cxx
+++ b/sc/source/filter/xml/XMLStylesExportHelper.cxx
@@ -1203,6 +1203,14 @@ rtl::OUString* ScColumnStyles::GetStyleName(const sal_Int32 nTable, const sal_In
 
 //===========================================================================
 
+ScRowStyles::Cache::Cache() :
+    mnTable(-1), mnStart(-1), mnEnd(-1), mnStyle(-1) {}
+
+bool ScRowStyles::Cache::hasCache(sal_Int32 nTable, sal_Int32 nField) const
+{
+    return mnTable == nTable && mnStart <= nField && nField <= mnEnd;
+}
+
 ScRowStyles::ScRowStyles()
     : ScColumnRowStylesBase()
 {
@@ -1225,12 +1233,24 @@ void ScRowStyles::AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields)
 sal_Int32 ScRowStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField)
 {
     DBG_ASSERT(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
+    if (maCache.hasCache(nTable, nField))
+        // Cache hit !
+        return maCache.mnStyle;
+
     StylesType& r = aTables[nTable];
     if (!r.is_tree_valid())
         r.build_tree();
     sal_Int32 nStyle;
-    if (r.search_tree(nField, nStyle))
+    sal_Int32 nStart, nEnd;
+    if (r.search_tree(nField, nStyle, &nStart, &nEnd))
+    {
+        // Cache this value for better performance.
+        maCache.mnTable = nTable;
+        maCache.mnStart = nStart;
+        maCache.mnEnd = nEnd;
+        maCache.mnStyle = nStyle;
         return nStyle;
+    }
 
     return -1;
 }
diff --git a/sc/source/filter/xml/XMLStylesExportHelper.hxx b/sc/source/filter/xml/XMLStylesExportHelper.hxx
index 5824382..368ec44 100644
--- a/sc/source/filter/xml/XMLStylesExportHelper.hxx
+++ b/sc/source/filter/xml/XMLStylesExportHelper.hxx
@@ -277,6 +277,17 @@ class ScRowStyles : public ScColumnRowStylesBase
 {
     typedef ::mdds::flat_segment_tree<sal_Int32, sal_Int32> StylesType;
     ::boost::ptr_vector<StylesType> aTables;
+    struct Cache
+    {
+        sal_Int32 mnTable;
+        sal_Int32 mnStart;
+        sal_Int32 mnEnd;
+        sal_Int32 mnStyle;
+        Cache();
+
+        bool hasCache(sal_Int32 nTable, sal_Int32 nField) const;
+    };
+    Cache maCache;
 
 public:
     ScRowStyles();
commit 8ad4dae2cef16c1525b5296c71626a5f4c45e68e
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Tue Nov 30 23:26:34 2010 -0500

    Replaced the inner vector with flat_segment_tree.
    
    This dramatically reduced memory footprint per sheet during export
    to ods.  With my test doc with 293 sheets, the resident memory size
    dropped from 1.4 GB to 270 MB.

diff --git a/sc/source/filter/xml/XMLStylesExportHelper.cxx b/sc/source/filter/xml/XMLStylesExportHelper.cxx
index 100d8ed..c551fb4 100644
--- a/sc/source/filter/xml/XMLStylesExportHelper.cxx
+++ b/sc/source/filter/xml/XMLStylesExportHelper.cxx
@@ -1218,28 +1218,29 @@ void ScRowStyles::AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields)
     if (nTable > nSize)
         for (sal_Int32 i = nSize; i < nTable; ++i)
         {
-            aTables.push_back(new ScMysalInt32Vec(nFields + 1, -1));
+            aTables.push_back(new StylesType(0, nFields+1, -1));
         }
 }
 
 sal_Int32 ScRowStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField)
 {
     DBG_ASSERT(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
-    if (static_cast<size_t>(nField) < aTables[nTable].size())
-        return aTables[nTable][nField];
-    else
-        return aTables[nTable][aTables[nTable].size() - 1];
+    StylesType& r = aTables[nTable];
+    if (!r.is_tree_valid())
+        r.build_tree();
+    sal_Int32 nStyle;
+    if (r.search_tree(nField, nStyle))
+        return nStyle;
+
+    return -1;
 }
 
 void ScRowStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField,
     const sal_Int32 nStringIndex)
 {
     DBG_ASSERT(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
-    DBG_ASSERT(aTables[nTable].size() >= static_cast<size_t>(nField), "wrong field");
-    if (aTables[nTable].size() == static_cast<size_t>(nField))
-        aTables[nTable].push_back(nStringIndex);
-    else
-        aTables[nTable][nField] = nStringIndex;
+    StylesType& r = aTables[nTable];
+    r.insert_back(nField, nField+1, nStringIndex);
 }
 
 void ScRowStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nStartField,
@@ -1247,19 +1248,8 @@ void ScRowStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nSta
 {
     DBG_ASSERT( nStartField <= nEndField, "bad field range");
     DBG_ASSERT(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
-    DBG_ASSERT(aTables[nTable].size() >= static_cast<size_t>(nStartField), "wrong field");
-    ScMysalInt32Vec& rTable = aTables[nTable];
-    size_t nSize = rTable.size();
-    if (nSize == static_cast<size_t>(nStartField))
-        rTable.insert( rTable.end(), static_cast<size_t>(nEndField - nStartField + 1), nStringIndex);
-    else
-    {
-        size_t nField = static_cast<size_t>(nStartField);
-        for ( ; nField < nSize && nField <= static_cast<size_t>(nEndField); ++nField)
-            rTable[nField] = nStringIndex;
-        if (nField <= static_cast<size_t>(nEndField))
-            rTable.insert( rTable.end(), static_cast<size_t>(nEndField - nField + 1), nStringIndex);
-    }
+    StylesType& r = aTables[nTable];
+    r.insert_back(nStartField, nEndField+1, nStringIndex);
 }
 
 rtl::OUString* ScRowStyles::GetStyleName(const sal_Int32 nTable, const sal_Int32 nField)
diff --git a/sc/source/filter/xml/XMLStylesExportHelper.hxx b/sc/source/filter/xml/XMLStylesExportHelper.hxx
index 7f0fa92..5824382 100644
--- a/sc/source/filter/xml/XMLStylesExportHelper.hxx
+++ b/sc/source/filter/xml/XMLStylesExportHelper.hxx
@@ -275,8 +275,8 @@ public:
 
 class ScRowStyles : public ScColumnRowStylesBase
 {
-    typedef std::vector<sal_Int32>       ScMysalInt32Vec;
-    ::boost::ptr_vector<ScMysalInt32Vec> aTables;
+    typedef ::mdds::flat_segment_tree<sal_Int32, sal_Int32> StylesType;
+    ::boost::ptr_vector<StylesType> aTables;
 
 public:
     ScRowStyles();
commit 9e867a01bb326e96e0e383cd023fe37f0a1776ae
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Tue Nov 30 16:01:55 2010 -0500

    Replaced std::vector with boost::ptr_vector.
    
    Nested std::vector does excessive copying of inner vector instances
    behind the scene.  Using ptr_vector to store the pointers to the
    inner vector instances avoids that.  Doing this alone cuts memory
    footprint per sheet when exporting document to .ods file.

diff --git a/sc/source/filter/xml/XMLStylesExportHelper.cxx b/sc/source/filter/xml/XMLStylesExportHelper.cxx
index 4bcdbd5..100d8ed 100644
--- a/sc/source/filter/xml/XMLStylesExportHelper.cxx
+++ b/sc/source/filter/xml/XMLStylesExportHelper.cxx
@@ -1204,8 +1204,7 @@ rtl::OUString* ScColumnStyles::GetStyleName(const sal_Int32 nTable, const sal_In
 //===========================================================================
 
 ScRowStyles::ScRowStyles()
-    : ScColumnRowStylesBase(),
-    aTables()
+    : ScColumnRowStylesBase()
 {
 }
 
@@ -1219,8 +1218,7 @@ void ScRowStyles::AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields)
     if (nTable > nSize)
         for (sal_Int32 i = nSize; i < nTable; ++i)
         {
-            ScMysalInt32Vec aFieldsVec(nFields + 1, -1);
-            aTables.push_back(aFieldsVec);
+            aTables.push_back(new ScMysalInt32Vec(nFields + 1, -1));
         }
 }
 
diff --git a/sc/source/filter/xml/XMLStylesExportHelper.hxx b/sc/source/filter/xml/XMLStylesExportHelper.hxx
index 767d6bf..7f0fa92 100644
--- a/sc/source/filter/xml/XMLStylesExportHelper.hxx
+++ b/sc/source/filter/xml/XMLStylesExportHelper.hxx
@@ -38,6 +38,9 @@
 #include <com/sun/star/sheet/ValidationAlertStyle.hpp>
 #include <com/sun/star/sheet/ValidationType.hpp>
 
+#include <boost/ptr_container/ptr_vector.hpp>
+#include <mdds/flat_segment_tree.hpp>
+
 class ScDocument;
 class ScXMLExport;
 
@@ -272,9 +275,8 @@ public:
 
 class ScRowStyles : public ScColumnRowStylesBase
 {
-    typedef std::vector<sal_Int32>	        ScMysalInt32Vec;
-    typedef std::vector<ScMysalInt32Vec>    ScMyRowVectorVec;
-    ScMyRowVectorVec				aTables;
+    typedef std::vector<sal_Int32>       ScMysalInt32Vec;
+    ::boost::ptr_vector<ScMysalInt32Vec> aTables;
 
 public:
     ScRowStyles();


More information about the Libreoffice-commits mailing list