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

Matúš Kukan matus.kukan at collabora.com
Mon Oct 6 05:42:37 PDT 2014


 sax/source/tools/CachedOutputStream.hxx |    9 ----
 sax/source/tools/fastserializer.cxx     |   58 +++++++++++++++++---------------
 sax/source/tools/fastserializer.hxx     |    1 
 3 files changed, 32 insertions(+), 36 deletions(-)

New commits:
commit f387b15fea0406b792b4ae5dc9f1c7ff9df78f38
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Mon Oct 6 14:45:07 2014 +0200

    Revert "FastSerializer: Add simpler writeByte method for single characters."
    
    Let's not do this. It's slower anyway, at least with clang.
    
    This reverts commit d0bff8fb54cb473037b6b1819e04f679881150f0.

diff --git a/sax/source/tools/CachedOutputStream.hxx b/sax/source/tools/CachedOutputStream.hxx
index a6a2cfc..fc74118 100644
--- a/sax/source/tools/CachedOutputStream.hxx
+++ b/sax/source/tools/CachedOutputStream.hxx
@@ -100,15 +100,6 @@ public:
         mnCacheWrittenSize += nLen;
     }
 
-    void writeByte( const sal_Int8 cChar )
-    {
-        // Write when the buffer gets big enough
-        if (mnCacheWrittenSize + 1 > mnMaximumSize)
-            flush();
-
-        *(pSeq->elements + mnCacheWrittenSize++) = cChar;
-    }
-
     /// immediately write buffer into mxOutputStream and clear
     void flush()
     {
diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx
index ff089fd..ac8376b 100644
--- a/sax/source/tools/fastserializer.cxx
+++ b/sax/source/tools/fastserializer.cxx
@@ -43,6 +43,14 @@ using ::com::sun::star::io::XOutputStream;
 // number of characters without terminating 0
 #define N_CHARS(string) (SAL_N_ELEMENTS(string) - 1)
 
+static const char sClosingBracket[] = ">";
+static const char sSlashAndClosingBracket[] = "/>";
+static const char sColon[] = ":";
+static const char sOpeningBracket[] = "<";
+static const char sOpeningBracketAndSlash[] = "</";
+static const char sQuote[] = "\"";
+static const char sEqualSignAndQuote[] = "=\"";
+static const char sSpace[] = " ";
 static const char sXmlHeader[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
 
 namespace sax_fastparser {
@@ -103,10 +111,10 @@ namespace sax_fastparser {
                 case '"':   writeBytes( """, 6 );   break;
                 case '\n':  writeBytes( "
", 5 );    break;
                 case '\r':  writeBytes( "
", 5 );    break;
-                default:    writeByte( cChar );          break;
+                default:    writeBytes( &cChar, 1 );     break;
             }
             else
-                writeByte( cChar );
+                writeBytes( &cChar, 1 );
         }
     }
 
@@ -138,7 +146,7 @@ namespace sax_fastparser {
                 case '"':   writeBytes( """, 6 );   break;
                 case '\n':  writeBytes( "
", 5 );    break;
                 case '\r':  writeBytes( "
", 5 );    break;
-                default:    writeByte( c );              break;
+                default:    writeBytes( &c, 1 );          break;
             }
         }
     }
@@ -153,7 +161,7 @@ namespace sax_fastparser {
     {
         if( HAS_NAMESPACE( nElement ) ) {
             writeBytes(mxFastTokenHandler->getUTF8Identifier(NAMESPACE(nElement)));
-            writeByte(':');
+            writeBytes(sColon, N_CHARS(sColon));
             writeBytes(mxFastTokenHandler->getUTF8Identifier(TOKEN(nElement)));
         } else
             writeBytes(mxFastTokenHandler->getUTF8Identifier(nElement));
@@ -167,7 +175,8 @@ namespace sax_fastparser {
                 mxFastTokenHandler->getUTF8Identifier(NAMESPACE(nElement)));
             Sequence<sal_Int8> const name(
                 mxFastTokenHandler->getUTF8Identifier(TOKEN(nElement)));
-            return OString(reinterpret_cast<sal_Char const*>(ns.getConstArray()), ns.getLength()) + ":"
+            return OString(reinterpret_cast<sal_Char const*>(ns.getConstArray()), ns.getLength())
+                 + OString(sColon, N_CHARS(sColon))
                  + OString(reinterpret_cast<sal_Char const*>(name.getConstArray()), name.getLength());
         } else {
             Sequence<sal_Int8> const name(
@@ -189,7 +198,7 @@ namespace sax_fastparser {
         m_DebugStartedElements.push(Element);
 #endif
 
-        writeByte('<');
+        writeBytes(sOpeningBracket, N_CHARS(sOpeningBracket));
 
         writeId(Element);
         if (pAttrList)
@@ -197,7 +206,7 @@ namespace sax_fastparser {
         else
             writeTokenValueList();
 
-        writeByte('>');
+        writeBytes(sClosingBracket, N_CHARS(sClosingBracket));
     }
 
     void FastSaxSerializer::endFastElement( ::sal_Int32 Element )
@@ -209,10 +218,11 @@ namespace sax_fastparser {
         m_DebugStartedElements.pop();
 #endif
 
-        writeByte('<');
-        writeByte('/');
+        writeBytes(sOpeningBracketAndSlash, N_CHARS(sOpeningBracketAndSlash));
+
         writeId(Element);
-        writeByte('>');
+
+        writeBytes(sClosingBracket, N_CHARS(sClosingBracket));
     }
 
     void FastSaxSerializer::singleFastElement( ::sal_Int32 Element, FastAttributeList* pAttrList )
@@ -223,7 +233,7 @@ namespace sax_fastparser {
             maMarkStack.top()->setCurrentElement( Element );
         }
 
-        writeByte('<');
+        writeBytes(sOpeningBracket, N_CHARS(sOpeningBracket));
 
         writeId(Element);
         if (pAttrList)
@@ -231,8 +241,7 @@ namespace sax_fastparser {
         else
             writeTokenValueList();
 
-        writeByte('/');
-        writeByte('>');
+        writeBytes(sSlashAndClosingBracket, N_CHARS(sSlashAndClosingBracket));
     }
 
     ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > FastSaxSerializer::getOutputStream()
@@ -247,7 +256,7 @@ namespace sax_fastparser {
 #endif
         for (size_t j = 0; j < maTokenValues.size(); j++)
         {
-            writeByte(' ');
+            writeBytes(sSpace, N_CHARS(sSpace));
 
             sal_Int32 nToken = maTokenValues[j].nToken;
             writeId(nToken);
@@ -259,10 +268,11 @@ namespace sax_fastparser {
             DebugAttributes.insert(nameId);
 #endif
 
-            writeByte('=');
-            writeByte('"');
+            writeBytes(sEqualSignAndQuote, N_CHARS(sEqualSignAndQuote));
+
             write(maTokenValues[j].pValue, -1, true);
-            writeByte('"');
+
+            writeBytes(sQuote, N_CHARS(sQuote));
         }
         maTokenValues.clear();
     }
@@ -275,7 +285,7 @@ namespace sax_fastparser {
         const std::vector< sal_Int32 >& Tokens = pAttrList->getFastAttributeTokens();
         for (size_t j = 0; j < Tokens.size(); j++)
         {
-            writeByte(' ');
+            writeBytes(sSpace, N_CHARS(sSpace));
 
             sal_Int32 nToken = Tokens[j];
             writeId(nToken);
@@ -287,10 +297,11 @@ namespace sax_fastparser {
             DebugAttributes.insert(nameId);
 #endif
 
-            writeByte('=');
-            writeByte('"');
+            writeBytes(sEqualSignAndQuote, N_CHARS(sEqualSignAndQuote));
+
             write(pAttrList->getFastAttributeValue(j), pAttrList->AttributeValueLength(j), true);
-            writeByte('"');
+
+            writeBytes(sQuote, N_CHARS(sQuote));
         }
     }
 
@@ -362,11 +373,6 @@ namespace sax_fastparser {
         maCachedOutputStream.writeBytes( reinterpret_cast<const sal_Int8*>(pStr), nLen );
     }
 
-    void FastSaxSerializer::writeByte( const sal_Int8 cChar )
-    {
-        maCachedOutputStream.writeByte( cChar );
-    }
-
     FastSaxSerializer::Int8Sequence& FastSaxSerializer::ForMerge::getData()
     {
         merge( maData, maPostponed, true );
diff --git a/sax/source/tools/fastserializer.hxx b/sax/source/tools/fastserializer.hxx
index 0b924bc..8500b68 100644
--- a/sax/source/tools/fastserializer.hxx
+++ b/sax/source/tools/fastserializer.hxx
@@ -228,7 +228,6 @@ private:
      */
     void writeBytes( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData );
     void writeBytes( const char* pStr, size_t nLen );
-    void writeByte( const sal_Int8 cChar );
 };
 
 } // namespace sax_fastparser


More information about the Libreoffice-commits mailing list