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

Michael Meeks michael.meeks at collabora.com
Fri Oct 11 05:54:02 PDT 2013


 sax/source/fastparser/fastparser.cxx |   28 +++++++++++++++++++++++-----
 sax/source/fastparser/fastparser.hxx |    3 +++
 2 files changed, 26 insertions(+), 5 deletions(-)

New commits:
commit e5f9e9fbc50cfd8b85f8216c38b1589321019f0a
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Fri Oct 11 13:51:47 2013 +0100

    fastparser: don't allocate uno::Sequences when we don't need to.
    
    Change-Id: Ic2fff8cabbc077b6fc9dabffd2c6fcf555152b11

diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index c3d5aeb..724856b 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -345,6 +345,7 @@ void Entity::endElement()
 FastSaxParser::FastSaxParser()
 {
     mxDocumentLocator.set( new FastLocatorImpl( this ) );
+    maUtf8Buffer.realloc( mnUtf8BufferSize );
 }
 
 // --------------------------------------------------------------------
@@ -377,19 +378,36 @@ void FastSaxParser::DefineNamespace( const OString& rPrefix, const sal_Char* pNa
 
 sal_Int32 FastSaxParser::GetToken( const OString& rToken )
 {
-    Sequence< sal_Int8 > aSeq( (sal_Int8*)rToken.getStr(), rToken.getLength() );
-
-    return getEntity().mxTokenHandler->getTokenFromUTF8( aSeq );
+    return GetToken( rToken.getStr(), rToken.getLength() );
 }
 
 sal_Int32 FastSaxParser::GetToken( const sal_Char* pToken, sal_Int32 nLen /* = 0 */ )
 {
+    sal_Int32 nRet;
+
     if( !nLen )
         nLen = strlen( pToken );
 
-    Sequence< sal_Int8 > aSeq( (sal_Int8*)pToken, nLen );
+    if ( nLen < mnUtf8BufferSize )
+    {
+        // Get intimiate with the underlying sequence cf. sal/types.h
+        sal_Sequence *pSeq = maUtf8Buffer.get();
+
+        sal_Int32 nPreRefCount = pSeq->nRefCount;
+
+        pSeq->nElements = nLen;
+        memcpy( pSeq->elements, pToken, nLen );
+        nRet = getEntity().mxTokenHandler->getTokenFromUTF8( maUtf8Buffer );
 
-    return getEntity().mxTokenHandler->getTokenFromUTF8( aSeq );
+        (void)nPreRefCount; // for non-debug mode.
+        assert( pSeq->nRefCount == nPreRefCount ); // callee must not take ref.
+    }
+    else
+    {
+        Sequence< sal_Int8 > aSeq( (sal_Int8*)pToken, nLen ); // heap allocate & free
+        nRet = getEntity().mxTokenHandler->getTokenFromUTF8( aSeq );
+    }
+    return nRet;
 }
 
 // --------------------------------------------------------------------
diff --git a/sax/source/fastparser/fastparser.hxx b/sax/source/fastparser/fastparser.hxx
index 13be254..5b387c4 100644
--- a/sax/source/fastparser/fastparser.hxx
+++ b/sax/source/fastparser/fastparser.hxx
@@ -202,6 +202,9 @@ private:
 
     ParserData maData;                      /// Cached parser configuration for next call of parseStream().
     ::std::stack< Entity > maEntities;      /// Entity stack for each call of parseStream().
+
+    static const int mnUtf8BufferSize = 128;
+    ::css::uno::Sequence< sal_Int8 > maUtf8Buffer; /// avoid constantly re-allocating this
 };
 
 }


More information about the Libreoffice-commits mailing list