[Libreoffice-commits] core.git: 11 commits - include/sax oox/source sax/source sc/source

Matúš Kukan matus.kukan at collabora.com
Thu Oct 23 05:12:35 PDT 2014


 include/sax/fshelper.hxx                     |    2 
 oox/source/core/xmlfilterbase.cxx            |    7 -
 oox/source/token/tokenmap.cxx                |    2 
 sax/source/tools/CachedOutputStream.hxx      |   46 +++--------
 sax/source/tools/fastserializer.cxx          |  104 +++++++++++++++++++--------
 sax/source/tools/fastserializer.hxx          |   25 ++++--
 sax/source/tools/fshelper.cxx                |   43 ++++-------
 sc/source/core/tool/address.cxx              |   86 +++++++++++-----------
 sc/source/filter/excel/xecontent.cxx         |   12 +--
 sc/source/filter/excel/xeextlst.cxx          |    2 
 sc/source/filter/excel/xestream.cxx          |    7 +
 sc/source/filter/excel/xetable.cxx           |    2 
 sc/source/filter/inc/xeroot.hxx              |    3 
 sc/source/filter/inc/xestream.hxx            |    3 
 sc/source/filter/xcl97/XclExpChangeTrack.cxx |    2 
 15 files changed, 190 insertions(+), 156 deletions(-)

New commits:
commit 25eba216d8b0201bcadb6d4f23484f9ec8f123a2
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Fri Oct 3 10:41:18 2014 +0200

    FastSerializer: Use -1 for unknown string length
    
    Change-Id: I3920caf9d95f20992b7961873f1668468d797e8e

diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx
index d885768..3876609 100644
--- a/sax/source/tools/fastserializer.cxx
+++ b/sax/source/tools/fastserializer.cxx
@@ -113,7 +113,7 @@ namespace sax_fastparser {
 
     void FastSaxSerializer::write( const char* pStr, sal_Int32 nLen, bool bEscape )
     {
-        if (nLen == 0)
+        if (nLen == -1)
             nLen = strlen(pStr);
 
         if (!bEscape)
@@ -251,7 +251,7 @@ namespace sax_fastparser {
 
             writeBytes(sEqualSignAndQuote, N_CHARS(sEqualSignAndQuote));
 
-            write(maTokenValues[j].pValue, 0, true);
+            write(maTokenValues[j].pValue, -1, true);
 
             writeBytes(sQuote, N_CHARS(sQuote));
         }
diff --git a/sax/source/tools/fshelper.cxx b/sax/source/tools/fshelper.cxx
index e0ed751..801be10 100644
--- a/sax/source/tools/fshelper.cxx
+++ b/sax/source/tools/fshelper.cxx
@@ -102,7 +102,7 @@ void FastSerializerHelper::singleElement(sal_Int32 elementTokenId, XFastAttribut
 
 FastSerializerHelper* FastSerializerHelper::write(const char* value)
 {
-    mpSerializer->write(value, 0, false);
+    mpSerializer->write(value, -1, false);
     return this;
 }
 
@@ -132,13 +132,14 @@ FastSerializerHelper* FastSerializerHelper::write(double value)
 
 FastSerializerHelper* FastSerializerHelper::writeEscaped(const char* value)
 {
-    mpSerializer->write(value, 0, true);
+    mpSerializer->write(value, -1, true);
     return this;
 }
 
 FastSerializerHelper* FastSerializerHelper::writeEscaped(const OUString& value)
 {
-    mpSerializer->write(value, true);
+    if (!value.isEmpty())
+        mpSerializer->write(value, true);
     return this;
 }
 
commit f39d69f6b5bc6dad1112e9465e12395d9439effb
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Fri Oct 3 11:16:39 2014 +0200

    Remove few pointless OUString::number() and one method
    
    Change-Id: I3e9a302a7513eebfeff07402f71fc3dde22e4cc2

diff --git a/include/sax/fshelper.hxx b/include/sax/fshelper.hxx
index 1f3b1b8..50248ce 100644
--- a/include/sax/fshelper.hxx
+++ b/include/sax/fshelper.hxx
@@ -124,7 +124,6 @@ public:
 
     FastSerializerHelper* write(const char* value);
     FastSerializerHelper* write(const OUString& value);
-    FastSerializerHelper* write(const OString& value);
     FastSerializerHelper* write(sal_Int32 value);
     FastSerializerHelper* write(sal_Int64 value);
     FastSerializerHelper* write(double value);
diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx
index 9516b82..d5c3a24 100644
--- a/oox/source/core/xmlfilterbase.cxx
+++ b/oox/source/core/xmlfilterbase.cxx
@@ -524,7 +524,7 @@ static void
 writeElement( FSHelperPtr pDoc, sal_Int32 nXmlElement, const sal_Int32 nValue )
 {
     pDoc->startElement( nXmlElement, FSEND );
-    pDoc->write( OUString::number( nValue ) );
+    pDoc->write( nValue );
     pDoc->endElement( nXmlElement );
 }
 
@@ -677,7 +677,7 @@ writeAppProperties( XmlFilterBase& rSelf, Reference< XDocumentProperties > xProp
     {
             sal_Int32 nValue = 0;
             if (it->second >>= nValue)
-                writeElement(pAppProps, XML_Paragraphs, OUString::number(nValue));
+                writeElement(pAppProps, XML_Paragraphs, nValue);
     }
 
     uno::Reference<beans::XPropertyAccess> xUserDefinedProperties(xProperties->getUserDefinedProperties(), uno::UNO_QUERY);
@@ -719,10 +719,9 @@ writeCustomProperties( XmlFilterBase& rSelf, Reference< XDocumentProperties > xP
 
             OString aName = OUStringToOString( aprop[n].Name, RTL_TEXTENCODING_ASCII_US );
             // pid starts from 2 not from 1 as MS supports pid from 2
-            OString pid =  OUStringToOString( OUString::number(n + 2), RTL_TEXTENCODING_ASCII_US );
             pAppProps->startElement( XML_property ,
                 XML_fmtid,  "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}",
-                XML_pid,    pid,
+                XML_pid,    OString::number(n + 2),
                 XML_name,   aName,
                 FSEND);
 
diff --git a/sax/source/tools/fshelper.cxx b/sax/source/tools/fshelper.cxx
index 55be646..e0ed751 100644
--- a/sax/source/tools/fshelper.cxx
+++ b/sax/source/tools/fshelper.cxx
@@ -112,25 +112,22 @@ FastSerializerHelper* FastSerializerHelper::write(const OUString& value)
     return this;
 }
 
-FastSerializerHelper* FastSerializerHelper::write(const OString& value)
-{
-    mpSerializer->write(value);
-    return this;
-}
-
 FastSerializerHelper* FastSerializerHelper::write(sal_Int32 value)
 {
-    return write(OString::number(value));
+    mpSerializer->write(OString::number(value));
+    return this;
 }
 
 FastSerializerHelper* FastSerializerHelper::write(sal_Int64 value)
 {
-    return write(OString::number(value));
+    mpSerializer->write(OString::number(value));
+    return this;
 }
 
 FastSerializerHelper* FastSerializerHelper::write(double value)
 {
-    return write(OString::number(value));
+    mpSerializer->write(OString::number(value));
+    return this;
 }
 
 FastSerializerHelper* FastSerializerHelper::writeEscaped(const char* value)
commit c0c45cad415b2d091c632f3c2bc15103597db1f9
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Thu Oct 2 10:26:00 2014 +0200

    maTokenNames.size() is constant: use it and be a bit faster
    
    Change-Id: I39a6e2badf0c159e87763e2782bc89f0ee6068ec

diff --git a/oox/source/token/tokenmap.cxx b/oox/source/token/tokenmap.cxx
index 880d5c6..dcd7284 100644
--- a/oox/source/token/tokenmap.cxx
+++ b/oox/source/token/tokenmap.cxx
@@ -82,7 +82,7 @@ sal_Int32 TokenMap::getTokenFromUnicode( const OUString& rUnicodeName ) const
 
 Sequence< sal_Int8 > TokenMap::getUtf8TokenName( sal_Int32 nToken ) const
 {
-    if( (0 <= nToken) && (static_cast< size_t >( nToken ) < maTokenNames.size()) )
+    if( (0 <= nToken) && (static_cast< size_t >( nToken ) < XML_TOKEN_COUNT) )
         return maTokenNames[ static_cast< size_t >( nToken ) ];
     return Sequence< sal_Int8 >();
 }
commit 5f46a7ad02aac2464fa45e4ecbc7cf4b85777664
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Thu Oct 2 12:02:40 2014 +0200

    FastSerializer: Faster write(OUString): add ascii check
    
    Saves about 80m pcycles for 180k calls.
    
    Change-Id: I9c9b3bf5a076df56d1b5b87f0a85ac3404abe8a4

diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx
index 7afdc4d..d885768 100644
--- a/sax/source/tools/fastserializer.cxx
+++ b/sax/source/tools/fastserializer.cxx
@@ -53,6 +53,15 @@ static const char sEqualSignAndQuote[] = "=\"";
 static const char sSpace[] = " ";
 static const char sXmlHeader[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
 
+static bool lcl_isAscii(const OUString& sStr)
+{
+    for (sal_Int32 i = 0; i < sStr.getLength(); ++i)
+        if (sStr[i] & 0xff80)
+            return false;
+
+    return true;
+}
+
 namespace sax_fastparser {
     FastSaxSerializer::FastSaxSerializer( const css::uno::Reference< css::io::XOutputStream >& xOutputStream )
         : maCachedOutputStream()
@@ -72,7 +81,29 @@ namespace sax_fastparser {
 
     void FastSaxSerializer::write( const OUString& sOutput, bool bEscape )
     {
-        write( OUStringToOString(sOutput, RTL_TEXTENCODING_UTF8), bEscape );
+        if (!lcl_isAscii(sOutput))
+        {
+            write( OUStringToOString(sOutput, RTL_TEXTENCODING_UTF8), bEscape );
+            return ;
+        }
+
+        for (sal_Int32 i = 0; i < sOutput.getLength(); ++i)
+        {
+            char c = sOutput[ i ];
+            if (bEscape) switch( c )
+            {
+                case '<':   writeBytes( "<", 4 );     break;
+                case '>':   writeBytes( ">", 4 );     break;
+                case '&':   writeBytes( "&", 5 );    break;
+                case '\'':  writeBytes( "'", 6 );   break;
+                case '"':   writeBytes( """, 6 );   break;
+                case '\n':  writeBytes( "
", 5 );    break;
+                case '\r':  writeBytes( "
", 5 );    break;
+                default:    writeBytes( &c, 1 );          break;
+            }
+            else
+                writeBytes( &c, 1 );
+        }
     }
 
     void FastSaxSerializer::write( const OString& sOutput, bool bEscape )
commit eb8e7a76328408bc12ff4abb761d7f44c27bf402
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Wed Oct 1 18:45:23 2014 +0200

    FastSerializer: Simplify a bit
    
    Change-Id: I7dee908f5441ad34128d688e1008fd6ffad2ab3f

diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx
index 8ea04d2..7afdc4d 100644
--- a/sax/source/tools/fastserializer.cxx
+++ b/sax/source/tools/fastserializer.cxx
@@ -19,7 +19,9 @@
 
 #include "fastserializer.hxx"
 
+#include <com/sun/star/xml/sax/FastTokenHandler.hpp>
 #include <rtl/ustrbuf.hxx>
+#include <comphelper/processfactory.hxx>
 #include <comphelper/sequenceasvector.hxx>
 
 #include <string.h>
@@ -52,11 +54,14 @@ static const char sSpace[] = " ";
 static const char sXmlHeader[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
 
 namespace sax_fastparser {
-    FastSaxSerializer::FastSaxSerializer( )
+    FastSaxSerializer::FastSaxSerializer( const css::uno::Reference< css::io::XOutputStream >& xOutputStream )
         : maCachedOutputStream()
-        , mxFastTokenHandler()
         , maMarkStack()
     {
+        mxFastTokenHandler = css::xml::sax::FastTokenHandler::create(
+                ::comphelper::getProcessComponentContext());
+        assert(xOutputStream.is()); // cannot do anything without that
+        maCachedOutputStream.setOutputStream( xOutputStream );
     }
     FastSaxSerializer::~FastSaxSerializer() {}
 
@@ -189,21 +194,11 @@ namespace sax_fastparser {
         writeBytes(sSlashAndClosingBracket, N_CHARS(sSlashAndClosingBracket));
     }
 
-    void FastSaxSerializer::setOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutputStream )
-    {
-        maCachedOutputStream.setOutputStream( xOutputStream );
-    }
-
     ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > FastSaxSerializer::getOutputStream()
     {
         return maCachedOutputStream.getOutputStream();
     }
 
-    void FastSaxSerializer::setFastTokenHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& xFastTokenHandler )
-    {
-        mxFastTokenHandler = xFastTokenHandler;
-    }
-
     void FastSaxSerializer::writeTokenValueList()
     {
 #ifdef DBG_UTIL
diff --git a/sax/source/tools/fastserializer.hxx b/sax/source/tools/fastserializer.hxx
index 6e81c91..60ef71b 100644
--- a/sax/source/tools/fastserializer.hxx
+++ b/sax/source/tools/fastserializer.hxx
@@ -48,7 +48,7 @@ class FastSaxSerializer
     typedef ::com::sun::star::uno::Sequence< ::sal_Int32 > Int32Sequence;
 
 public:
-    FastSaxSerializer();
+    FastSaxSerializer( const css::uno::Reference< css::io::XOutputStream >& xOutputStream );
     ~FastSaxSerializer();
 
     ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > getOutputStream();
@@ -106,9 +106,6 @@ public:
     */
     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 );
-
     // C++ helpers
     void writeId( ::sal_Int32 Element );
     OString getId( ::sal_Int32 Element );
diff --git a/sax/source/tools/fshelper.cxx b/sax/source/tools/fshelper.cxx
index 2227352..55be646 100644
--- a/sax/source/tools/fshelper.cxx
+++ b/sax/source/tools/fshelper.cxx
@@ -19,9 +19,7 @@
 
 #include <sax/fshelper.hxx>
 #include "fastserializer.hxx"
-#include <com/sun/star/xml/sax/FastTokenHandler.hpp>
 #include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
-#include <comphelper/processfactory.hxx>
 #include <rtl/ustrbuf.hxx>
 
 using namespace ::com::sun::star;
@@ -30,12 +28,8 @@ using namespace ::com::sun::star::uno;
 namespace sax_fastparser {
 
 FastSerializerHelper::FastSerializerHelper(const Reference< io::XOutputStream >& xOutputStream, bool bWriteHeader ) :
-    mpSerializer(new FastSaxSerializer())
+    mpSerializer(new FastSaxSerializer(xOutputStream))
 {
-    Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext(), UNO_SET_THROW );
-    mpSerializer->setFastTokenHandler( css::xml::sax::FastTokenHandler::create(xContext) );
-    assert(xOutputStream.is()); // cannot do anything without that
-    mpSerializer->setOutputStream( xOutputStream );
     if( bWriteHeader )
         mpSerializer->startDocument();
 }
commit 865fc150ea61b49dc28a56f287096efae0621163
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Wed Oct 1 18:24:58 2014 +0200

    Unused includes / using-declarations
    
    Change-Id: I8b43635ab1f77b61469f060c9a092f1494388955

diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx
index 6d46cda..8ea04d2 100644
--- a/sax/source/tools/fastserializer.cxx
+++ b/sax/source/tools/fastserializer.cxx
@@ -19,9 +19,6 @@
 
 #include "fastserializer.hxx"
 
-#include <com/sun/star/xml/Attribute.hpp>
-#include <com/sun/star/xml/FastAttribute.hpp>
-
 #include <rtl/ustrbuf.hxx>
 #include <comphelper/sequenceasvector.hxx>
 
@@ -34,15 +31,9 @@
 
 using ::comphelper::SequenceAsVector;
 using ::com::sun::star::uno::Reference;
-using ::com::sun::star::uno::RuntimeException;
 using ::com::sun::star::uno::Sequence;
-using ::com::sun::star::xml::FastAttribute;
 using ::com::sun::star::xml::Attribute;
-using ::com::sun::star::xml::sax::SAXException;
 using ::com::sun::star::io::XOutputStream;
-using ::com::sun::star::io::NotConnectedException;
-using ::com::sun::star::io::IOException;
-using ::com::sun::star::io::BufferSizeExceededException;
 
 #define HAS_NAMESPACE(x) ((x & 0xffff0000) != 0)
 #define NAMESPACE(x) (x >> 16)
commit 5ed4c11534ba431097da1abb5d600d21b5f68a9a
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Wed Oct 1 17:39:00 2014 +0200

    Use sc::CompileFormulaContext for faster export
    
    It's a cache for maTabNames (sheet names mangled for the current grammar
    for output) which ScCompiler needs and is expensive to get.
    
    Change-Id: I7e2954104427a3c220f0f097be6cd45a66485b56

diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index 5e5f9cd..b7d5f36 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -937,13 +937,13 @@ void XclExpCFImpl::SaveXml( XclExpXmlStream& rStrm )
     if(!IsTextRule(eOperation) && !IsTopBottomRule(eOperation))
     {
         rWorksheet->startElement( XML_formula, FSEND );
-        rWorksheet->writeEscaped(XclXmlUtils::ToOUString( GetRoot().GetDoc(), mrFormatEntry.GetValidSrcPos(),
+        rWorksheet->writeEscaped(XclXmlUtils::ToOUString( GetCompileFormulaContext(), mrFormatEntry.GetValidSrcPos(),
                     mrFormatEntry.CreateTokenArry(0)));
         rWorksheet->endElement( XML_formula );
         if (bFmla2)
         {
             rWorksheet->startElement( XML_formula, FSEND );
-            rWorksheet->writeEscaped(XclXmlUtils::ToOUString( GetRoot().GetDoc(), mrFormatEntry.GetValidSrcPos(),
+            rWorksheet->writeEscaped(XclXmlUtils::ToOUString( GetCompileFormulaContext(), mrFormatEntry.GetValidSrcPos(),
                         mrFormatEntry.CreateTokenArry(1)));
             rWorksheet->endElement( XML_formula );
         }
@@ -1082,7 +1082,7 @@ void XclExpCfvo::SaveXml( XclExpXmlStream& rStrm )
     OString aValue;
     if(mrEntry.GetType() == COLORSCALE_FORMULA)
     {
-        OUString aFormula = XclXmlUtils::ToOUString( GetRoot().GetDoc(), maSrcPos,
+        OUString aFormula = XclXmlUtils::ToOUString( GetCompileFormulaContext(), maSrcPos,
                 mrEntry.GetFormula()->Clone());
         aValue = OUStringToOString(aFormula, RTL_TEXTENCODING_UTF8 );
     }
@@ -1583,7 +1583,7 @@ XclExpDV::XclExpDV( const XclExpRoot& rRoot, sal_uLong nScHandle ) :
                         Formula compiler supports this by offering two different functions
                         CreateDataValFormula() and CreateListValFormula(). */
                     mxTokArr1 = rFmlaComp.CreateFormula( EXC_FMLATYPE_LISTVAL, *xScTokArr );
-                    msFormula1 = XclXmlUtils::ToOUString( GetDoc(), pValData->GetSrcPos(),
+                    msFormula1 = XclXmlUtils::ToOUString( GetCompileFormulaContext(), pValData->GetSrcPos(),
                             xScTokArr.get());
                 }
             }
@@ -1591,7 +1591,7 @@ XclExpDV::XclExpDV( const XclExpRoot& rRoot, sal_uLong nScHandle ) :
             {
                 // no list validation -> convert the formula
                 mxTokArr1 = rFmlaComp.CreateFormula( EXC_FMLATYPE_DATAVAL, *xScTokArr );
-                msFormula1 = XclXmlUtils::ToOUString( GetDoc(), pValData->GetSrcPos(),
+                msFormula1 = XclXmlUtils::ToOUString( GetCompileFormulaContext(), pValData->GetSrcPos(),
                         xScTokArr.get());
             }
         }
@@ -1601,7 +1601,7 @@ XclExpDV::XclExpDV( const XclExpRoot& rRoot, sal_uLong nScHandle ) :
         if( xScTokArr.get() )
         {
             mxTokArr2 = rFmlaComp.CreateFormula( EXC_FMLATYPE_DATAVAL, *xScTokArr );
-            msFormula2 = XclXmlUtils::ToOUString( GetDoc(), pValData->GetSrcPos(),
+            msFormula2 = XclXmlUtils::ToOUString( GetCompileFormulaContext(), pValData->GetSrcPos(),
                     xScTokArr.get());
         }
     }
diff --git a/sc/source/filter/excel/xeextlst.cxx b/sc/source/filter/excel/xeextlst.cxx
index 852647c..bb96e27 100644
--- a/sc/source/filter/excel/xeextlst.cxx
+++ b/sc/source/filter/excel/xeextlst.cxx
@@ -62,7 +62,7 @@ XclExpExtCfvo::XclExpExtCfvo( const XclExpRoot& rRoot, const ScColorScaleEntry&
         OUString aFormula;
         if(pArr)
         {
-            aFormula = XclXmlUtils::ToOUString( GetRoot().GetDoc(), rSrcPos,
+            aFormula = XclXmlUtils::ToOUString( GetCompileFormulaContext(), rSrcPos,
                     pArr->Clone());
         }
         maValue = OUStringToOString(aFormula, RTL_TEXTENCODING_UTF8 );
diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx
index 31e39c7..9d1adb0 100644
--- a/sc/source/filter/excel/xestream.cxx
+++ b/sc/source/filter/excel/xestream.cxx
@@ -39,6 +39,7 @@
 #include "compiler.hxx"
 #include "formulacell.hxx"
 #include "tokenarray.hxx"
+#include "tokenstringcontext.hxx"
 #include "refreshtimerprotector.hxx"
 #include "globstr.hrc"
 
@@ -810,9 +811,10 @@ OUString XclXmlUtils::ToOUString( const ScfUInt16Vec& rBuf, sal_Int32 nStart, sa
 }
 
 OUString XclXmlUtils::ToOUString(
-    ScDocument& rDocument, const ScAddress& rAddress, const ScTokenArray* pTokenArray )
+    sc::CompileFormulaContext& rCtx, const ScAddress& rAddress, const ScTokenArray* pTokenArray )
 {
-    ScCompiler aCompiler( &rDocument, rAddress, const_cast<ScTokenArray&>(*pTokenArray));
+    ScCompiler aCompiler( rCtx, rAddress, const_cast<ScTokenArray&>(*pTokenArray));
+
     aCompiler.SetGrammar(FormulaGrammar::GRAM_OOXML);
 
     OUStringBuffer aBuffer( pTokenArray->GetLen() * 5 );
@@ -1077,6 +1079,7 @@ bool XclExpXmlStream::exportDocument()
     aData.maMaxPos.SetCol( ::std::min( aData.maScMaxPos.Col(), aData.maXclMaxPos.Col() ) );
     aData.maMaxPos.SetRow( ::std::min( aData.maScMaxPos.Row(), aData.maXclMaxPos.Row() ) );
     aData.maMaxPos.SetTab( ::std::min( aData.maScMaxPos.Tab(), aData.maXclMaxPos.Tab() ) );
+    aData.mpCompileFormulaCxt.reset( new sc::CompileFormulaContext(&rDoc) );
 
     XclExpRoot aRoot( aData );
 
diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx
index 97a31c6..cae6460 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -946,7 +946,7 @@ void XclExpFormulaCell::SaveXml( XclExpXmlStream& rStrm )
             // OOXTODO: XML_bx      bool
             FSEND );
     rWorksheet->writeEscaped( XclXmlUtils::ToOUString(
-        *mrScFmlaCell.GetDocument(), mrScFmlaCell.aPos, mrScFmlaCell.GetCode()));
+        rStrm.GetRoot().GetCompileFormulaContext(), mrScFmlaCell.aPos, mrScFmlaCell.GetCode()));
     rWorksheet->endElement( XML_f );
     if( strcmp( sType, "inlineStr" ) == 0 )
     {
diff --git a/sc/source/filter/inc/xeroot.hxx b/sc/source/filter/inc/xeroot.hxx
index 35de5c6..698b0e4 100644
--- a/sc/source/filter/inc/xeroot.hxx
+++ b/sc/source/filter/inc/xeroot.hxx
@@ -52,6 +52,7 @@ class XclExpFilterManager;
 class XclExpPivotTableManager;
 class XclExpDxfs;
 class XclExpXmlPivotTableManager;
+namespace sc { class CompileFormulaContext; }
 
 /** Stores global buffers and data needed for Excel export filter. */
 struct XclExpRootData : public XclRootData
@@ -92,6 +93,7 @@ struct XclExpRootData : public XclRootData
     XclExpDxfsRef       mxDxfs;             /// All delta formatting entries
 
     boost::shared_ptr<XclExpXmlPivotTableManager> mxXmlPTableMgr;
+    boost::shared_ptr<sc::CompileFormulaContext> mpCompileFormulaCxt;
 
     ScCompiler::OpCodeMapPtr  mxOpCodeMap;  /// mapping between op-codes and names
 
@@ -112,6 +114,7 @@ public:
     inline const XclExpRoot& GetRoot() const { return *this; }
     /** Returns true, if URLs should be stored relative to the document location. */
     inline bool         IsRelUrl() const { return mrExpData.mbRelUrl; }
+    sc::CompileFormulaContext& GetCompileFormulaContext() const { return *mrExpData.mpCompileFormulaCxt; }
 
     /** Returns the buffer for Calc->Excel sheet index conversion. */
     XclExpTabInfo&      GetTabInfo() const;
diff --git a/sc/source/filter/inc/xestream.hxx b/sc/source/filter/inc/xestream.hxx
index c705e45..df1f7a3 100644
--- a/sc/source/filter/inc/xestream.hxx
+++ b/sc/source/filter/inc/xestream.hxx
@@ -251,6 +251,7 @@ struct XclAddress;
 struct XclFontData;
 struct XclRange;
 class XclRangeList;
+namespace sc { class CompileFormulaContext; }
 
 class XclXmlUtils
 {
@@ -275,7 +276,7 @@ public:
 
     static OUString ToOUString( const char* s );
     static OUString ToOUString( const ScfUInt16Vec& rBuffer, sal_Int32 nStart = 0, sal_Int32 nLength = -1 );
-    static OUString ToOUString( ScDocument& rDocument, const ScAddress& rAddress, const ScTokenArray* pTokenArray );
+    static OUString ToOUString( sc::CompileFormulaContext& rCtx, const ScAddress& rAddress, const ScTokenArray* pTokenArray );
     static OUString ToOUString( const XclExpString& s );
 
     /**
diff --git a/sc/source/filter/xcl97/XclExpChangeTrack.cxx b/sc/source/filter/xcl97/XclExpChangeTrack.cxx
index 83cdd57..04a64eb 100644
--- a/sc/source/filter/xcl97/XclExpChangeTrack.cxx
+++ b/sc/source/filter/xcl97/XclExpChangeTrack.cxx
@@ -1032,7 +1032,7 @@ static void lcl_WriteCell( XclExpXmlStream& rStrm, sal_Int32 nElement, const ScA
                     // OOXTODO: other attributes?  see XclExpFormulaCell::SaveXml()
                     FSEND );
             pStream->writeEscaped( XclXmlUtils::ToOUString(
-                        *pData->mpFormulaCell->GetDocument(),
+                        rStrm.GetRoot().GetCompileFormulaContext(),
                         pData->mpFormulaCell->aPos, pData->mpFormulaCell->GetCode()));
             pStream->endElement( XML_f );
             break;
commit d8af144254b8f10fe1faa40f9072aad043ca35fe
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 );
 }
 
commit eb195bbe34f1d7b794c2927e2e7053404758bc44
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Tue Sep 30 15:13:22 2014 +0200

    Use OUStringBuffers for performance reasons.
    
    Saves 120m pcycles in just 250k calls to ScAddress::Format.
    
    Change-Id: Ibf20cf0843a47cf0fa37a38c4fecf1ae1560412c

diff --git a/sc/source/core/tool/address.cxx b/sc/source/core/tool/address.cxx
index 6a37952..c8c8f18 100644
--- a/sc/source/core/tool/address.cxx
+++ b/sc/source/core/tool/address.cxx
@@ -1656,50 +1656,50 @@ sal_uInt16 ScRange::ParseRows( const OUString& rStr, ScDocument* pDoc,
     return (p != NULL && *p == '\0') ? nRes : 0;
 }
 
-static inline void lcl_a1_append_c ( OUString &rString, int nCol, bool bIsAbs )
+static inline void lcl_a1_append_c ( OUStringBuffer &rString, int nCol, bool bIsAbs )
 {
     if( bIsAbs )
-        rString += "$";
+        rString.append("$");
     ScColToAlpha( rString, sal::static_int_cast<SCCOL>(nCol) );
 }
 
-static inline void lcl_a1_append_r ( OUString &rString, int nRow, bool bIsAbs )
+static inline void lcl_a1_append_r ( OUStringBuffer &rString, int nRow, bool bIsAbs )
 {
     if ( bIsAbs )
-        rString += "$";
-    rString += OUString::number( nRow+1 );
+        rString.append("$");
+    rString.append(OUString::number( nRow+1 ));
 }
 
-static inline void lcl_r1c1_append_c ( OUString &rString, int nCol, bool bIsAbs,
+static inline void lcl_r1c1_append_c ( OUStringBuffer &rString, int nCol, bool bIsAbs,
                                        const ScAddress::Details& rDetails )
 {
-    rString += "C";
+    rString.append("C");
     if (bIsAbs)
     {
-        rString += OUString::number( nCol + 1 );
+        rString.append(OUString::number( nCol + 1 ));
     }
     else
     {
         nCol -= rDetails.nCol;
         if (nCol != 0) {
-            rString += "[" + OUString::number( nCol ) + "]";
+            rString.append("[").append(OUString::number( nCol )).append("]");
         }
     }
 }
 
-static inline void lcl_r1c1_append_r ( OUString &rString, int nRow, bool bIsAbs,
+static inline void lcl_r1c1_append_r ( OUStringBuffer &rString, int nRow, bool bIsAbs,
                                        const ScAddress::Details& rDetails )
 {
-    rString += "R";
+    rString.append("R");
     if (bIsAbs)
     {
-        rString += OUString::number( nRow + 1 );
+        rString.append(OUString::number( nRow + 1 ));
     }
     else
     {
         nRow -= rDetails.nRow;
         if (nRow != 0) {
-            rString += "[" + OUString::number( nRow ) + "]";
+            rString.append("[").append(OUString::number( nRow )).append("]");
         }
     }
 }
@@ -1732,7 +1732,7 @@ static OUString getFileNameFromDoc( const ScDocument* pDoc )
 OUString ScAddress::Format(sal_uInt16 nFlags, const ScDocument* pDoc,
                            const Details& rDetails) const
 {
-    OUString r;
+    OUStringBuffer r;
     if( nFlags & SCA_VALID )
         nFlags |= ( SCA_VALID_ROW | SCA_VALID_COL | SCA_VALID_TAB );
     if( pDoc && (nFlags & SCA_VALID_TAB ) )
@@ -1770,11 +1770,11 @@ OUString ScAddress::Format(sal_uInt16 nFlags, const ScDocument* pDoc,
             {
             default :
             case formula::FormulaGrammar::CONV_OOO:
-                r += aDocName;
+                r.append(aDocName);
                 if( nFlags & SCA_TAB_ABSOLUTE )
-                    r += "$";
-                r += aTabName;
-                r += ".";
+                    r.append("$");
+                r.append(aTabName);
+                r.append(".");
                 break;
 
             case formula::FormulaGrammar::CONV_XL_A1:
@@ -1782,10 +1782,10 @@ OUString ScAddress::Format(sal_uInt16 nFlags, const ScDocument* pDoc,
             case formula::FormulaGrammar::CONV_XL_OOX:
                 if (!aDocName.isEmpty())
                 {
-                    r += "[" + aDocName + "]";
+                    r.append("[").append(aDocName).append("]");
                 }
-                r += aTabName;
-                r += "!";
+                r.append(aTabName);
+                r.append("!");
                 break;
             }
         }
@@ -1809,7 +1809,7 @@ OUString ScAddress::Format(sal_uInt16 nFlags, const ScDocument* pDoc,
             lcl_r1c1_append_c ( r, nCol, (nFlags & SCA_COL_ABSOLUTE) != 0, rDetails );
         break;
     }
-    return r;
+    return r.makeStringAndClear();
 }
 
 static void lcl_Split_DocTab( const ScDocument* pDoc,  SCTAB nTab,
@@ -1841,7 +1841,7 @@ static void lcl_Split_DocTab( const ScDocument* pDoc,  SCTAB nTab,
     ScCompiler::CheckTabQuotes( rTabName, rDetails.eConv);
 }
 
-static void lcl_ScRange_Format_XL_Header( OUString& rString, const ScRange& rRange,
+static void lcl_ScRange_Format_XL_Header( OUStringBuffer& rString, const ScRange& rRange,
                                           sal_uInt16 nFlags, const ScDocument* pDoc,
                                           const ScAddress::Details& rDetails )
 {
@@ -1852,18 +1852,18 @@ static void lcl_ScRange_Format_XL_Header( OUString& rString, const ScRange& rRan
                           aTabName, aDocName );
         if( !aDocName.isEmpty() )
         {
-            rString += "[" + aDocName + "]";
+            rString.append("[").append(aDocName).append("]");
         }
-        rString += aTabName;
+        rString.append(aTabName);
 
         if( nFlags & SCA_TAB2_3D )
         {
             lcl_Split_DocTab( pDoc, rRange.aEnd.Tab(), rDetails, nFlags,
                               aTabName, aDocName );
-            rString += ":";
-            rString += aTabName;
+            rString.append(":");
+            rString.append(aTabName);
         }
-        rString += "!";
+        rString.append("!");
     }
 }
 
@@ -1875,7 +1875,7 @@ OUString ScRange::Format( sal_uInt16 nFlags, const ScDocument* pDoc,
         return ScGlobal::GetRscString( STR_NOREF_STR );
     }
 
-    OUString r;
+    OUStringBuffer r;
 #define absrel_differ(nFlags, mask) (((nFlags) & (mask)) ^ (((nFlags) >> 4) & (mask)))
     switch( rDetails.eConv ) {
     default :
@@ -1894,8 +1894,8 @@ OUString ScRange::Format( sal_uInt16 nFlags, const ScDocument* pDoc,
             else
                 nFlags |= SCA_TAB_3D;
             OUString aName(aEnd.Format(nFlags, pDoc, rDetails));
-            r += ":";
-            r += aName;
+            r.append(":");
+            r.append(aName);
         }
     }
     break;
@@ -1907,14 +1907,14 @@ OUString ScRange::Format( sal_uInt16 nFlags, const ScDocument* pDoc,
         {
             // Full col refs always require 2 rows (2:2)
             lcl_a1_append_r( r, aStart.Row(), (nFlags & SCA_ROW_ABSOLUTE) != 0 );
-            r += ":";
+            r.append(":");
             lcl_a1_append_r( r, aEnd.Row(), (nFlags & SCA_ROW2_ABSOLUTE) != 0 );
         }
         else if( aStart.Row() == 0 && aEnd.Row() >= MAXROW )
         {
             // Full row refs always require 2 cols (A:A)
             lcl_a1_append_c( r, aStart.Col(), (nFlags & SCA_COL_ABSOLUTE) != 0 );
-            r += ":";
+            r.append(":");
             lcl_a1_append_c( r, aEnd.Col(), (nFlags & SCA_COL2_ABSOLUTE) != 0 );
         }
         else
@@ -1925,7 +1925,7 @@ OUString ScRange::Format( sal_uInt16 nFlags, const ScDocument* pDoc,
                 absrel_differ( nFlags, SCA_COL_ABSOLUTE ) ||
                 aStart.Row() != aEnd.Row() ||
                 absrel_differ( nFlags, SCA_ROW_ABSOLUTE )) {
-                r += ":";
+                r.append(":");
                 lcl_a1_append_c ( r, aEnd.Col(), (nFlags & SCA_COL2_ABSOLUTE) != 0 );
                 lcl_a1_append_r ( r, aEnd.Row(), (nFlags & SCA_ROW2_ABSOLUTE) != 0 );
             }
@@ -1939,7 +1939,7 @@ OUString ScRange::Format( sal_uInt16 nFlags, const ScDocument* pDoc,
             lcl_r1c1_append_r( r, aStart.Row(), (nFlags & SCA_ROW_ABSOLUTE) != 0, rDetails );
             if( aStart.Row() != aEnd.Row() ||
                 absrel_differ( nFlags, SCA_ROW_ABSOLUTE )) {
-                r += ":";
+                r.append(":");
                 lcl_r1c1_append_r( r, aEnd.Row(), (nFlags & SCA_ROW2_ABSOLUTE) != 0, rDetails );
             }
         }
@@ -1948,7 +1948,7 @@ OUString ScRange::Format( sal_uInt16 nFlags, const ScDocument* pDoc,
             lcl_r1c1_append_c( r, aStart.Col(), (nFlags & SCA_COL_ABSOLUTE) != 0, rDetails );
             if( aStart.Col() != aEnd.Col() ||
                 absrel_differ( nFlags, SCA_COL_ABSOLUTE )) {
-                r += ":";
+                r.append(":");
                 lcl_r1c1_append_c( r, aEnd.Col(), (nFlags & SCA_COL2_ABSOLUTE) != 0, rDetails );
             }
         }
@@ -1960,14 +1960,14 @@ OUString ScRange::Format( sal_uInt16 nFlags, const ScDocument* pDoc,
                 absrel_differ( nFlags, SCA_COL_ABSOLUTE ) ||
                 aStart.Row() != aEnd.Row() ||
                 absrel_differ( nFlags, SCA_ROW_ABSOLUTE )) {
-                r += ":";
+                r.append(":");
                 lcl_r1c1_append_r( r, aEnd.Row(), (nFlags & SCA_ROW2_ABSOLUTE) != 0, rDetails );
                 lcl_r1c1_append_c( r, aEnd.Col(), (nFlags & SCA_COL2_ABSOLUTE) != 0, rDetails );
             }
         }
     }
 #undef  absrel_differ
-    return r;
+    return r.makeStringAndClear();
 }
 
 bool ScAddress::Move( SCsCOL dx, SCsROW dy, SCsTAB dz, ScDocument* pDoc )
@@ -2003,7 +2003,7 @@ bool ScRange::Move( SCsCOL dx, SCsROW dy, SCsTAB dz, ScDocument* pDoc )
 OUString ScAddress::GetColRowString( bool bAbsolute,
                                    const Details& rDetails ) const
 {
-    OUString aString;
+    OUStringBuffer aString;
 
     switch( rDetails.eConv )
     {
@@ -2012,14 +2012,14 @@ OUString ScAddress::GetColRowString( bool bAbsolute,
     case formula::FormulaGrammar::CONV_XL_A1:
     case formula::FormulaGrammar::CONV_XL_OOX:
     if (bAbsolute)
-        aString += "$";
+        aString.append("$");
 
     ScColToAlpha( aString, nCol);
 
     if ( bAbsolute )
-        aString += "$";
+        aString.append("$");
 
-    aString += OUString::number(nRow+1);
+    aString.append(OUString::number(nRow+1));
         break;
 
     case formula::FormulaGrammar::CONV_XL_R1C1:
@@ -2028,7 +2028,7 @@ OUString ScAddress::GetColRowString( bool bAbsolute,
         break;
     }
 
-    return aString;
+    return aString.makeStringAndClear();
 }
 
 OUString ScRefAddress::GetRefString( ScDocument* pDoc, SCTAB nActTab,
commit dbbbea666251175c2a4f9b0387d53ff097c65872
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Tue Sep 30 13:53:26 2014 +0200

    FastSerializer: Simplify cache to be fixed sized buffer
    
    This makes writeBytes(), which is called a lot, simpler and thus faster.
    E.g. for ~15m calls, this saves ~110m pcycles.
    
    Change-Id: I29d01a1a8651f668aff574e0f015cd2f018eb1cd

diff --git a/sax/source/tools/CachedOutputStream.hxx b/sax/source/tools/CachedOutputStream.hxx
index 56b17fb..82c2b66 100644
--- a/sax/source/tools/CachedOutputStream.hxx
+++ b/sax/source/tools/CachedOutputStream.hxx
@@ -22,28 +22,17 @@ namespace sax_fastparser {
 
 class CachedOutputStream
 {
-    /// realloc aligns to this value
-    static const sal_Int32 mnMinimumResize = 0x1000;
     /// When buffer hits this size, it's written to mxOutputStream
     static const sal_Int32 mnMaximumSize = 0x10000;
 
     /// Output stream, usually writing data into files.
     css::uno::Reference< css::io::XOutputStream > mxOutputStream;
-    sal_Int32 mnCacheAllocatedSize;
     sal_Int32 mnCacheWrittenSize;
-    sal_Int8* mpCache;
+    sal_Int8 mpCache[ mnMaximumSize ];
 
 public:
-    CachedOutputStream() : mnCacheAllocatedSize(mnMinimumResize)
-                         , mnCacheWrittenSize(0)
-    {
-        mpCache = static_cast<sal_Int8 *>(malloc(mnCacheAllocatedSize));
-    }
-
-    ~CachedOutputStream()
-    {
-        free(mpCache);
-    }
+    CachedOutputStream() : mnCacheWrittenSize(0) {}
+    ~CachedOutputStream() {}
 
     css::uno::Reference< css::io::XOutputStream > getOutputStream() const
     {
@@ -58,30 +47,21 @@ public:
     /// cache string and if limit is hit, flush
     void writeBytes( const sal_Int8* pStr, sal_Int32 nLen )
     {
-        // Writer does some elements sorting, so it can accumulate
-        // pretty big strings in FastSaxSerializer::ForMerge.
-        // In that case, just flush data and write immediately.
-        if (nLen > mnMaximumSize)
-        {
-            flush();
-            mxOutputStream->writeBytes( css::uno::Sequence<sal_Int8>(pStr, nLen) );
-            return;
-        }
-
         // Write when the buffer gets big enough
         if (mnCacheWrittenSize + nLen > mnMaximumSize)
+        {
             flush();
 
-        sal_Int32 nMissingBytes = mnCacheWrittenSize + nLen - mnCacheAllocatedSize;
-        // Ensure the buffer has enough space left
-        if (nMissingBytes > 0)
-        {
-            // Round off to the next multiple of mnMinimumResize
-            mnCacheAllocatedSize = mnCacheAllocatedSize +
-                ((nMissingBytes + mnMinimumResize - 1) / mnMinimumResize) * mnMinimumResize;
-            mpCache = static_cast<sal_Int8 *>(realloc(mpCache, mnCacheAllocatedSize));
+            // Writer does some elements sorting, so it can accumulate
+            // pretty big strings in FastSaxSerializer::ForMerge.
+            // In that case, just flush data and write immediately.
+            if (nLen > mnMaximumSize)
+            {
+                mxOutputStream->writeBytes( css::uno::Sequence<sal_Int8>(pStr, nLen) );
+                return;
+            }
         }
-        assert(mnCacheWrittenSize + nLen <= mnCacheAllocatedSize);
+
         memcpy(mpCache + mnCacheWrittenSize, pStr, nLen);
         mnCacheWrittenSize += nLen;
     }
commit 659064475d78b19f06a21985c4cc1feb50c9ca03
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Tue Sep 30 13:40:06 2014 +0200

    This was OString already; use it that way
    
    Change-Id: Ia2268ce8a1e2111adb609c515e5bfa824afa66ce

diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx
index 02c97e6..87c317c 100644
--- a/sax/source/tools/fastserializer.cxx
+++ b/sax/source/tools/fastserializer.cxx
@@ -210,7 +210,7 @@ namespace sax_fastparser {
     void FastSaxSerializer::writeFastAttributeList( FastAttributeList* pAttrList )
     {
 #ifdef DBG_UTIL
-        ::std::set<OUString> DebugAttributes;
+        ::std::set<OString> DebugAttributes;
 #endif
         const std::vector< sal_Int32 >& Tokens = pAttrList->getFastAttributeTokens();
         for (size_t j = 0; j < Tokens.size(); j++)
@@ -222,10 +222,9 @@ namespace sax_fastparser {
 
 #ifdef DBG_UTIL
             // Well-formedness constraint: Unique Att Spec
-            OUString const name(OStringToOUString(getId(nToken),
-                                                  RTL_TEXTENCODING_UTF8));
-            assert(DebugAttributes.find(name) == DebugAttributes.end());
-            DebugAttributes.insert(name);
+            OString const nameId(getId(nToken));
+            assert(DebugAttributes.find(nameId) == DebugAttributes.end());
+            DebugAttributes.insert(nameId);
 #endif
 
             writeBytes(sEqualSignAndQuote, N_CHARS(sEqualSignAndQuote));


More information about the Libreoffice-commits mailing list