[Libreoffice-commits] core.git: Branch 'private/kohei/xlsx-import-speedup' - 3 commits - include/oox oox/source sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Fri Nov 22 17:57:53 PST 2013


 include/oox/core/xmlfilterbase.hxx        |    8 -
 oox/source/core/xmlfilterbase.cxx         |  173 ++++++++++++++----------------
 sc/source/filter/inc/workbookhelper.hxx   |    6 -
 sc/source/filter/oox/workbookfragment.cxx |    9 +
 sc/source/filter/oox/workbookhelper.cxx   |    7 +
 5 files changed, 109 insertions(+), 94 deletions(-)

New commits:
commit 473bca0aad9757242a1b95d2c0cb0a500000abab
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Fri Nov 22 20:57:40 2013 -0500

    Allow worker threads to use their own FastParser instances.
    
    To prevent deadlock during threaded sheet stream parsing.  It now
    deadlocks at a different place.
    
    Change-Id: I0ba0f2c9a257e71b0a340ab14e369b06d5fd8829

diff --git a/include/oox/core/xmlfilterbase.hxx b/include/oox/core/xmlfilterbase.hxx
index 87234fb..76eb091 100644
--- a/include/oox/core/xmlfilterbase.hxx
+++ b/include/oox/core/xmlfilterbase.hxx
@@ -56,8 +56,7 @@ namespace oox {
 namespace core {
 
 class FragmentHandler;
-
-// ============================================================================
+class FastParser;
 
 struct TextField {
     com::sun::star::uno::Reference< com::sun::star::text::XText > xText;
@@ -107,7 +106,8 @@ public:
 
         @return  True, if the fragment could be imported.
      */
-    bool                importFragment( const ::rtl::Reference< FragmentHandler >& rxHandler );
+    bool importFragment( const rtl::Reference<FragmentHandler>& rxHandler );
+    bool importFragment( const rtl::Reference<FragmentHandler>& rxHandler, FastParser& rParser );
 
     /** Imports a fragment into an xml::dom::XDocument.
 
@@ -231,6 +231,8 @@ public:
 
     void importDocumentProperties();
 
+    FastParser* createParser() const;
+
 protected:
     virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
         implGetInputStream( utl::MediaDescriptor& rMediaDesc ) const;
diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx
index dddc29c..30f3848 100644
--- a/oox/source/core/xmlfilterbase.cxx
+++ b/oox/source/core/xmlfilterbase.cxx
@@ -143,6 +143,13 @@ struct NamespaceIds: public rtl::StaticWithInit<
     }
 };
 
+void registerNamespaces( FastParser& rParser )
+{
+    const Sequence< beans::Pair<OUString, sal_Int32> > ids = NamespaceIds::get();
+    for (sal_Int32 i = 0; i < ids.getLength(); ++i)
+        rParser.registerNamespace(ids[i].Second);
+}
+
 } // namespace
 
 struct XmlFilterBaseImpl
@@ -164,10 +171,7 @@ XmlFilterBaseImpl::XmlFilterBaseImpl( const Reference< XComponentContext >& rxCo
     maVmlSuffix( ".vml" )
 {
     // register XML namespaces
-    const Sequence< beans::Pair< OUString, sal_Int32 > > ids=
-        NamespaceIds::get();
-    for( sal_Int32 i=0; i<ids.getLength(); ++i )
-        maFastParser.registerNamespace( ids[i].Second );
+    registerNamespaces(maFastParser);
 }
 
 XmlFilterBase::XmlFilterBase( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
@@ -203,13 +207,25 @@ void XmlFilterBase::importDocumentProperties()
     xImporter->importProperties( xDocumentStorage, xPropSupplier->getDocumentProperties() );
 }
 
+FastParser* XmlFilterBase::createParser() const
+{
+    FastParser* pParser = new FastParser(getComponentContext());
+    registerNamespaces(*pParser);
+    return pParser;
+}
+
 OUString XmlFilterBase::getFragmentPathFromFirstType( const OUString& rType )
 {
     // importRelations() caches the relations map for subsequence calls
     return importRelations( OUString() )->getFragmentPathFromFirstType( rType );
 }
 
-bool XmlFilterBase::importFragment( const ::rtl::Reference< FragmentHandler >& rxHandler )
+bool XmlFilterBase::importFragment( const rtl::Reference<FragmentHandler>& rxHandler )
+{
+    return importFragment(rxHandler, mxImpl->maFastParser);
+}
+
+bool XmlFilterBase::importFragment( const rtl::Reference<FragmentHandler>& rxHandler, FastParser& rParser )
 {
     OSL_ENSURE( rxHandler.is(), "XmlFilterBase::importFragment - missing fragment handler" );
     if( !rxHandler.is() )
@@ -263,8 +279,8 @@ bool XmlFilterBase::importFragment( const ::rtl::Reference< FragmentHandler >& r
         // own try/catch block for showing parser failure assertion with fragment path
         if( xInStrm.is() ) try
         {
-            mxImpl->maFastParser.setDocumentHandler( xDocHandler );
-            mxImpl->maFastParser.parseStream( xInStrm, aFragmentPath );
+            rParser.setDocumentHandler(xDocHandler);
+            rParser.parseStream(xInStrm, aFragmentPath);
             return true;
         }
         catch( Exception& )
diff --git a/sc/source/filter/inc/workbookhelper.hxx b/sc/source/filter/inc/workbookhelper.hxx
index abafb20..1f472c3 100644
--- a/sc/source/filter/inc/workbookhelper.hxx
+++ b/sc/source/filter/inc/workbookhelper.hxx
@@ -53,6 +53,7 @@ namespace oox { namespace core {
     class FilterBase;
     class FragmentHandler;
     class XmlFilterBase;
+    class FastParser;
 } }
 
 class ScDocument;
@@ -269,7 +270,10 @@ public:
 
     /** Imports a fragment using the passed fragment handler, which contains
         the full path to the fragment stream. */
-    bool                importOoxFragment( const ::rtl::Reference< ::oox::core::FragmentHandler >& rxHandler );
+    bool importOoxFragment( const rtl::Reference<oox::core::FragmentHandler>& rxHandler );
+
+    bool importOoxFragment( const rtl::Reference<oox::core::FragmentHandler>& rxHandler, oox::core::FastParser& rParser );
+
 
     // BIFF2-BIFF8 specific (MUST NOT be called in OOXML/BIFF12 filter) -------
 
diff --git a/sc/source/filter/oox/workbookfragment.cxx b/sc/source/filter/oox/workbookfragment.cxx
index e9471cb..81eb2ed 100644
--- a/sc/source/filter/oox/workbookfragment.cxx
+++ b/sc/source/filter/oox/workbookfragment.cxx
@@ -49,6 +49,7 @@
 #include "globstr.hrc"
 #include "calcconfig.hxx"
 
+#include <oox/core/fastparser.hxx>
 #include <comphelper/processfactory.hxx>
 #include <officecfg/Office/Calc.hxx>
 #include <salhelper/thread.hxx>
@@ -240,13 +241,17 @@ class WorkerThread : public salhelper::Thread
     WorkbookFragment& mrWorkbookHandler;
     size_t mnID;
     FragmentHandlerRef mxHandler;
+    boost::scoped_ptr<oox::core::FastParser> mxParser;
     osl::Mutex maMtxAction;
     osl::Condition maCondActionChanged;
     WorkerAction meAction;
 public:
     WorkerThread( WorkbookFragment& rWorkbookHandler, size_t nID ) :
         salhelper::Thread("sheet-import-worker-thread"),
-        mrWorkbookHandler(rWorkbookHandler), mnID(nID), meAction(None) {}
+        mrWorkbookHandler(rWorkbookHandler),
+        mnID(nID),
+        mxParser(rWorkbookHandler.getOoxFilter().createParser()),
+        meAction(None) {}
 
     virtual void execute()
     {
@@ -271,7 +276,7 @@ public:
 
 #if 0
             // TODO : This still deadlocks in the fast parser code.
-            mrWorkbookHandler.importOoxFragment(mxHandler);
+            mrWorkbookHandler.importOoxFragment(mxHandler, *mxParser);
 #else
             double val = rand() / static_cast<double>(RAND_MAX);
             val *= 1000000; // normalize to 1 second.
diff --git a/sc/source/filter/oox/workbookhelper.cxx b/sc/source/filter/oox/workbookhelper.cxx
index 33270e5..66a51b4 100644
--- a/sc/source/filter/oox/workbookhelper.cxx
+++ b/sc/source/filter/oox/workbookhelper.cxx
@@ -961,11 +961,16 @@ XmlFilterBase& WorkbookHelper::getOoxFilter() const
     return mrBookGlob.getOoxFilter();
 }
 
-bool WorkbookHelper::importOoxFragment( const ::rtl::Reference< FragmentHandler >& rxHandler )
+bool WorkbookHelper::importOoxFragment( const rtl::Reference<FragmentHandler>& rxHandler )
 {
     return getOoxFilter().importFragment( rxHandler );
 }
 
+bool WorkbookHelper::importOoxFragment( const rtl::Reference<FragmentHandler>& rxHandler, oox::core::FastParser& rParser )
+{
+    return getOoxFilter().importFragment(rxHandler, rParser);
+}
+
 // BIFF specific --------------------------------------------------------------
 
 BiffType WorkbookHelper::getBiff() const
commit 3a521c144af3c63bda7b2349da786eb547dcf703
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Fri Nov 22 20:14:44 2013 -0500

    A bit of cleanup.
    
    Change-Id: I576a184ebc8422d760800c670f8d9070f66e9e78

diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx
index 3416dc7..dddc29c 100644
--- a/oox/source/core/xmlfilterbase.cxx
+++ b/oox/source/core/xmlfilterbase.cxx
@@ -58,8 +58,6 @@ using ::com::sun::star::xml::dom::XDocumentBuilder;
 namespace oox {
 namespace core {
 
-// ============================================================================
-
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::container;
@@ -74,12 +72,6 @@ using utl::MediaDescriptor;
 using ::sax_fastparser::FSHelperPtr;
 using ::sax_fastparser::FastSerializerHelper;
 
-
-
-
-
-// ============================================================================
-
 namespace {
 
 bool lclHasSuffix( const OUString& rFragmentPath, const OUString& rSuffix )
@@ -88,27 +80,6 @@ bool lclHasSuffix( const OUString& rFragmentPath, const OUString& rSuffix )
     return (nSuffixPos >= 0) && rFragmentPath.match( rSuffix, nSuffixPos );
 }
 
-} // namespace
-
-// ============================================================================
-
-struct XmlFilterBaseImpl
-{
-    typedef RefMap< OUString, Relations > RelationsMap;
-
-    FastParser                     maFastParser;
-    const OUString                 maBinSuffix;
-    const OUString                 maVmlSuffix;
-    RelationsMap                   maRelationsMap;
-    TextFieldStack                 maTextFieldStack;
-
-    explicit            XmlFilterBaseImpl( const Reference< XComponentContext >& rxContext ) throw( RuntimeException );
-};
-
-// ----------------------------------------------------------------------------
-
-namespace {
-
 struct NamespaceIds: public rtl::StaticWithInit<
     Sequence< beans::Pair< OUString, sal_Int32 > >,
     NamespaceIds>
@@ -172,9 +143,20 @@ struct NamespaceIds: public rtl::StaticWithInit<
     }
 };
 
-}
+} // namespace
 
-// ----------------------------------------------------------------------------
+struct XmlFilterBaseImpl
+{
+    typedef RefMap< OUString, Relations > RelationsMap;
+
+    FastParser                     maFastParser;
+    const OUString                 maBinSuffix;
+    const OUString                 maVmlSuffix;
+    RelationsMap                   maRelationsMap;
+    TextFieldStack                 maTextFieldStack;
+
+    explicit            XmlFilterBaseImpl( const Reference< XComponentContext >& rxContext ) throw( RuntimeException );
+};
 
 XmlFilterBaseImpl::XmlFilterBaseImpl( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
     maFastParser( rxContext ),
commit f4a1e57560bddedec53b8c5fa35520fa84531099
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Fri Nov 22 20:12:41 2013 -0500

    No indent on namespaces.
    
    Change-Id: I2639a51c2faa19373a335c28b160862435cd6dbe

diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx
index 98c8886..3416dc7 100644
--- a/oox/source/core/xmlfilterbase.cxx
+++ b/oox/source/core/xmlfilterbase.cxx
@@ -107,70 +107,71 @@ struct XmlFilterBaseImpl
 
 // ----------------------------------------------------------------------------
 
-namespace
+namespace {
+
+struct NamespaceIds: public rtl::StaticWithInit<
+    Sequence< beans::Pair< OUString, sal_Int32 > >,
+    NamespaceIds>
 {
-    struct NamespaceIds: public rtl::StaticWithInit<
-        Sequence< beans::Pair< OUString, sal_Int32 > >,
-        NamespaceIds>
+    Sequence< beans::Pair< OUString, sal_Int32 > > operator()()
     {
-        Sequence< beans::Pair< OUString, sal_Int32 > > operator()()
-        {
-            static const char* const namespaceURIs[] = {
-                "http://www.w3.org/XML/1998/namespace",
-                "http://schemas.openxmlformats.org/package/2006/relationships",
-                "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
-                "http://schemas.openxmlformats.org/drawingml/2006/main",
-                "http://schemas.openxmlformats.org/drawingml/2006/diagram",
-                "http://schemas.openxmlformats.org/drawingml/2006/chart",
-                "http://schemas.openxmlformats.org/drawingml/2006/chartDrawing",
-                "urn:schemas-microsoft-com:vml",
-                "urn:schemas-microsoft-com:office:office",
-                "urn:schemas-microsoft-com:office:word",
-                "urn:schemas-microsoft-com:office:excel",
-                "urn:schemas-microsoft-com:office:powerpoint",
-                "http://schemas.microsoft.com/office/2006/activeX",
-                "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
-                "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",
-                "http://schemas.microsoft.com/office/excel/2006/main",
-                "http://schemas.openxmlformats.org/presentationml/2006/main",
-                "http://schemas.openxmlformats.org/markup-compatibility/2006",
-                "http://schemas.openxmlformats.org/spreadsheetml/2006/main/v2",
-                "http://schemas.microsoft.com/office/drawing/2008/diagram",
-                "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
-            };
-
-            static const sal_Int32 namespaceIds[] = {
-                NMSP_xml,
-                NMSP_packageRel,
-                NMSP_officeRel,
-                NMSP_dml,
-                NMSP_dmlDiagram,
-                NMSP_dmlChart,
-                NMSP_dmlChartDr,
-                NMSP_dmlSpreadDr,
-                NMSP_vml,
-                NMSP_vmlOffice,
-                NMSP_vmlWord,
-                NMSP_vmlExcel,
-                NMSP_vmlPowerpoint,
-                NMSP_xls,
-                NMSP_ppt,
-                NMSP_ax,
-                NMSP_xm,
-                NMSP_mce,
-                NMSP_mceTest,
-                NMSP_dsp,
-                NMSP_xlsExtLst
-            };
-
-            Sequence< beans::Pair< OUString, sal_Int32 > > aRet(STATIC_ARRAY_SIZE(namespaceIds));
-            for( sal_Int32 i=0; i<aRet.getLength(); ++i )
-                aRet[i] = make_Pair(
-                    OUString::createFromAscii(namespaceURIs[i]),
-                    namespaceIds[i]);
-            return aRet;
-        }
-    };
+        static const char* const namespaceURIs[] = {
+            "http://www.w3.org/XML/1998/namespace",
+            "http://schemas.openxmlformats.org/package/2006/relationships",
+            "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
+            "http://schemas.openxmlformats.org/drawingml/2006/main",
+            "http://schemas.openxmlformats.org/drawingml/2006/diagram",
+            "http://schemas.openxmlformats.org/drawingml/2006/chart",
+            "http://schemas.openxmlformats.org/drawingml/2006/chartDrawing",
+            "urn:schemas-microsoft-com:vml",
+            "urn:schemas-microsoft-com:office:office",
+            "urn:schemas-microsoft-com:office:word",
+            "urn:schemas-microsoft-com:office:excel",
+            "urn:schemas-microsoft-com:office:powerpoint",
+            "http://schemas.microsoft.com/office/2006/activeX",
+            "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
+            "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",
+            "http://schemas.microsoft.com/office/excel/2006/main",
+            "http://schemas.openxmlformats.org/presentationml/2006/main",
+            "http://schemas.openxmlformats.org/markup-compatibility/2006",
+            "http://schemas.openxmlformats.org/spreadsheetml/2006/main/v2",
+            "http://schemas.microsoft.com/office/drawing/2008/diagram",
+            "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
+        };
+
+        static const sal_Int32 namespaceIds[] = {
+            NMSP_xml,
+            NMSP_packageRel,
+            NMSP_officeRel,
+            NMSP_dml,
+            NMSP_dmlDiagram,
+            NMSP_dmlChart,
+            NMSP_dmlChartDr,
+            NMSP_dmlSpreadDr,
+            NMSP_vml,
+            NMSP_vmlOffice,
+            NMSP_vmlWord,
+            NMSP_vmlExcel,
+            NMSP_vmlPowerpoint,
+            NMSP_xls,
+            NMSP_ppt,
+            NMSP_ax,
+            NMSP_xm,
+            NMSP_mce,
+            NMSP_mceTest,
+            NMSP_dsp,
+            NMSP_xlsExtLst
+        };
+
+        Sequence< beans::Pair< OUString, sal_Int32 > > aRet(STATIC_ARRAY_SIZE(namespaceIds));
+        for( sal_Int32 i=0; i<aRet.getLength(); ++i )
+            aRet[i] = make_Pair(
+                OUString::createFromAscii(namespaceURIs[i]),
+                namespaceIds[i]);
+        return aRet;
+    }
+};
+
 }
 
 // ----------------------------------------------------------------------------


More information about the Libreoffice-commits mailing list