[Libreoffice-commits] core.git: Branch 'feature/perfwork' - include/sax sax/source

Matúš Kukan matus.kukan at collabora.com
Wed Oct 1 06:54:06 PDT 2014


 include/sax/fshelper.hxx            |    1 
 sax/source/tools/fastserializer.cxx |   38 ++++++++++++++++++++++++++++++++++--
 sax/source/tools/fastserializer.hxx |   20 +++++++++++++++---
 sax/source/tools/fshelper.cxx       |   13 +++++-------
 4 files changed, 58 insertions(+), 14 deletions(-)

New commits:
commit 4b7b677560014b6af82dfb43ceb114596ddccf4a
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Wed Oct 1 12:50:29 2014 +0200

    FastSerializer: Use faster TokenValue struct when possible
    
    Saves another ~100m pcycles for 650k calls in startElementInternal()
    
    Change-Id: I190326edc7feffb900e91fa7e5c3530b5b267f59

diff --git a/include/sax/fshelper.hxx b/include/sax/fshelper.hxx
index 5630910..1f3b1b8 100644
--- a/include/sax/fshelper.hxx
+++ b/include/sax/fshelper.hxx
@@ -183,7 +183,6 @@ private:
     void singleElementInternal(sal_Int32 elementTokenId, ...);
 
     FastSaxSerializer* mpSerializer;
-    FastAttributeList maAttrList;
 };
 
 typedef boost::shared_ptr< FastSerializerHelper > FSHelperPtr;
diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx
index 87c317c..6d46cda 100644
--- a/sax/source/tools/fastserializer.cxx
+++ b/sax/source/tools/fastserializer.cxx
@@ -158,7 +158,10 @@ namespace sax_fastparser {
         writeBytes(sOpeningBracket, N_CHARS(sOpeningBracket));
 
         writeId(Element);
-        writeFastAttributeList(pAttrList);
+        if (pAttrList)
+            writeFastAttributeList(pAttrList);
+        else
+            writeTokenValueList();
 
         writeBytes(sClosingBracket, N_CHARS(sClosingBracket));
     }
@@ -187,7 +190,10 @@ namespace sax_fastparser {
         writeBytes(sOpeningBracket, N_CHARS(sOpeningBracket));
 
         writeId(Element);
-        writeFastAttributeList(pAttrList);
+        if (pAttrList)
+            writeFastAttributeList(pAttrList);
+        else
+            writeTokenValueList();
 
         writeBytes(sSlashAndClosingBracket, N_CHARS(sSlashAndClosingBracket));
     }
@@ -207,6 +213,34 @@ namespace sax_fastparser {
         mxFastTokenHandler = xFastTokenHandler;
     }
 
+    void FastSaxSerializer::writeTokenValueList()
+    {
+#ifdef DBG_UTIL
+        ::std::set<OString> DebugAttributes;
+#endif
+        for (size_t j = 0; j < maTokenValues.size(); j++)
+        {
+            writeBytes(sSpace, N_CHARS(sSpace));
+
+            sal_Int32 nToken = maTokenValues[j].nToken;
+            writeId(nToken);
+
+#ifdef DBG_UTIL
+            // Well-formedness constraint: Unique Att Spec
+            OString const nameId(getId(nToken));
+            assert(DebugAttributes.find(nameId) == DebugAttributes.end());
+            DebugAttributes.insert(nameId);
+#endif
+
+            writeBytes(sEqualSignAndQuote, N_CHARS(sEqualSignAndQuote));
+
+            write(maTokenValues[j].pValue, 0, true);
+
+            writeBytes(sQuote, N_CHARS(sQuote));
+        }
+        maTokenValues.clear();
+    }
+
     void FastSaxSerializer::writeFastAttributeList( FastAttributeList* pAttrList )
     {
 #ifdef DBG_UTIL
diff --git a/sax/source/tools/fastserializer.hxx b/sax/source/tools/fastserializer.hxx
index 1b541c1..6e81c91 100644
--- a/sax/source/tools/fastserializer.hxx
+++ b/sax/source/tools/fastserializer.hxx
@@ -33,6 +33,14 @@
 
 namespace sax_fastparser {
 
+struct TokenValue
+{
+    sal_Int32   nToken;
+    const char *pValue;
+    TokenValue(sal_Int32 _nToken, const char *_pValue) : nToken(_nToken), pValue(_pValue) {}
+};
+typedef std::vector<TokenValue> TokenValueList;
+
 /// Receives notification of sax document events to write into an XOutputStream.
 class FastSaxSerializer
 {
@@ -44,6 +52,8 @@ public:
     ~FastSaxSerializer();
 
     ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > getOutputStream();
+    /// called by FSHelper to put data in for writeTokenValueList
+    TokenValueList& getTokenValueList() { return maTokenValues; }
 
     /** called by the parser when parsing of an XML stream is started.
      */
@@ -65,12 +75,12 @@ public:
             and the integer token of the namespace combined with an arithmetic
             <b>or</b> operation.
 
-        @param Attribs
+        @param pAttrList
             Contains a <type>FastAttributeList</type> to access the attributes
             from the element.
 
     */
-    void startFastElement( ::sal_Int32 Element, FastAttributeList* Attribs );
+    void startFastElement( ::sal_Int32 Element, FastAttributeList* pAttrList = NULL );
 
     /** receives notification of the end of an known element.
         @see startFastElement
@@ -89,12 +99,12 @@ public:
             and the integer token of the namespace combined with an arithmetic
             <b>or</b> operation.
 
-        @param Attribs
+        @param pAttrList
             Contains a <type>FastAttributeList</type> to access the attributes
             from the element.
 
     */
-    void singleFastElement( ::sal_Int32 Element, FastAttributeList* Attribs );
+    void singleFastElement( ::sal_Int32 Element, FastAttributeList* pAttrList = NULL );
 
     void setOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutputStream );
     void setFastTokenHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& xFastTokenHandler );
@@ -197,11 +207,13 @@ private:
     };
 
     ::std::stack< boost::shared_ptr< ForMerge > > maMarkStack;
+    TokenValueList maTokenValues;
 
 #ifdef DBG_UTIL
     ::std::stack<sal_Int32> m_DebugStartedElements;
 #endif
 
+    void writeTokenValueList();
     void writeFastAttributeList( FastAttributeList* pAttrList );
     void writeOutput( const sal_Int8* pStr, size_t nLen );
     void writeOutput( const css::uno::Sequence< ::sal_Int8 >& aData );
diff --git a/sax/source/tools/fshelper.cxx b/sax/source/tools/fshelper.cxx
index c6ac390..2227352 100644
--- a/sax/source/tools/fshelper.cxx
+++ b/sax/source/tools/fshelper.cxx
@@ -31,7 +31,6 @@ namespace sax_fastparser {
 
 FastSerializerHelper::FastSerializerHelper(const Reference< io::XOutputStream >& xOutputStream, bool bWriteHeader ) :
     mpSerializer(new FastSaxSerializer())
-  , maAttrList(Reference< xml::sax::XFastTokenHandler >())
 {
     Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext(), UNO_SET_THROW );
     mpSerializer->setFastTokenHandler( css::xml::sax::FastTokenHandler::create(xContext) );
@@ -51,7 +50,7 @@ void FastSerializerHelper::startElementInternal(sal_Int32 elementTokenId, ...)
 {
     va_list args;
     va_start( args, elementTokenId );
-    maAttrList.clear();
+    TokenValueList& rAttrList = mpSerializer->getTokenValueList();
 
     while (true)
     {
@@ -60,10 +59,10 @@ void FastSerializerHelper::startElementInternal(sal_Int32 elementTokenId, ...)
             break;
         const char* pValue = va_arg(args, const char*);
         if (pValue)
-            maAttrList.add(nName, pValue);
+            rAttrList.push_back(TokenValue(nName, pValue));
     }
 
-    mpSerializer->startFastElement(elementTokenId, &maAttrList);
+    mpSerializer->startFastElement(elementTokenId);
     va_end( args );
 }
 
@@ -71,7 +70,7 @@ void FastSerializerHelper::singleElementInternal(sal_Int32 elementTokenId, ...)
 {
     va_list args;
     va_start( args, elementTokenId );
-    maAttrList.clear();
+    TokenValueList& rAttrList = mpSerializer->getTokenValueList();
 
     while (true)
     {
@@ -80,10 +79,10 @@ void FastSerializerHelper::singleElementInternal(sal_Int32 elementTokenId, ...)
             break;
         const char* pValue = va_arg(args, const char*);
         if  (pValue)
-            maAttrList.add(nName, pValue);
+            rAttrList.push_back(TokenValue(nName, pValue));
     }
 
-    mpSerializer->singleFastElement(elementTokenId, &maAttrList);
+    mpSerializer->singleFastElement(elementTokenId);
     va_end( args );
 }
 


More information about the Libreoffice-commits mailing list