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

Michael Meeks michael.meeks at collabora.com
Fri Sep 26 02:55:22 PDT 2014


 include/sax/fastattribs.hxx          |   36 +++++++++++++++++------------------
 sax/source/fastparser/fastparser.cxx |    7 ++----
 sax/source/tools/fastattribs.cxx     |   25 ++++++++----------------
 3 files changed, 30 insertions(+), 38 deletions(-)

New commits:
commit 0ea1be53909d30a7fbe22f9c95f7b77ed0054fed
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Fri Sep 26 10:37:17 2014 +0100

    fastparser: avoid allocating un-used FastTokenLookup class.
    
    This contained an rtl_Sequence complete with horror internal
    allocator, caught red-handed serializing threaded loading to no
    good purpose.
    
    Change-Id: I837b2c17e4f70fd6a49bed33ad74a7d79f98f35c

diff --git a/include/sax/fastattribs.hxx b/include/sax/fastattribs.hxx
index 4724b7e..6d9c7a4 100644
--- a/include/sax/fastattribs.hxx
+++ b/include/sax/fastattribs.hxx
@@ -52,22 +52,24 @@ typedef std::vector< UnknownAttribute > UnknownAttributeList;
 /// A native C++ interface to tokenisation
 class SAX_DLLPUBLIC FastTokenHandlerBase
 {
-    public:
-        virtual ~FastTokenHandlerBase();
-        virtual sal_Int32 getTokenDirect( const char *pToken, sal_Int32 nLength ) const = 0;
-};
-
-/// avoid constantly allocating and freeing sequences.
-class SAX_DLLPUBLIC FastTokenLookup
-{
-    static const int mnUtf8BufferSize = 128;
-    css::uno::Sequence< sal_Int8 > maUtf8Buffer;
-public:
-    FastTokenLookup();
-    sal_Int32 getTokenFromChars(
-        const css::uno::Reference< css::xml::sax::XFastTokenHandler > &mxTokenHandler,
-        FastTokenHandlerBase *pTokenHandler,
-        const char *pStr, size_t nLength = 0 );
+ public:
+    virtual ~FastTokenHandlerBase();
+    virtual sal_Int32 getTokenDirect( const char *pToken, sal_Int32 nLength ) const = 0;
+
+    /**
+     * Client method to attempt the use of this interface if possible.
+     * @xTokenHandler - the UNO handle for the token lookup interface
+     * @pTokenHandler - a dynamic_cast version of @xTokenHandler to this interface
+     * @pStr - string buffer to lookup
+     * @nLength - optional length of chars in that buffer
+     *
+     * @return Tokenized form of pStr
+     */
+    static sal_Int32 getTokenFromChars(
+                         const css::uno::Reference<
+                             css::xml::sax::XFastTokenHandler > &xTokenHandler,
+                         FastTokenHandlerBase *pTokenHandler /* can be NULL */,
+                         const char *pStr, size_t nLength = 0 );
 };
 
 class SAX_DLLPUBLIC FastAttributeList : public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XFastAttributeList >
@@ -112,8 +114,6 @@ private:
     UnknownAttributeList maUnknownAttributes;
     ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler > mxTokenHandler;
     FastTokenHandlerBase *mpTokenHandler;
-
-    FastTokenLookup maTokenLookup;
 };
 
 }
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index fcbb58d..12429be 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -253,7 +253,6 @@ private:
 
     Entity *mpTop;                          /// std::stack::top() is amazingly slow => cache this.
     ::std::stack< Entity > maEntities;      /// Entity stack for each call of parseStream().
-    FastTokenLookup maTokenLookup;
 };
 
 } // namespace sax_fastparser
@@ -646,9 +645,9 @@ void FastSaxParserImpl::DefineNamespace( const OString& rPrefix, const sal_Char*
 
 sal_Int32 FastSaxParserImpl::GetToken( const sal_Char* pToken, sal_Int32 nLen /* = 0 */ )
 {
-    return maTokenLookup.getTokenFromChars( getEntity().mxTokenHandler,
-                                            getEntity().mpTokenHandler,
-                                            pToken, nLen );
+    return FastTokenHandlerBase::getTokenFromChars( getEntity().mxTokenHandler,
+                                                    getEntity().mpTokenHandler,
+                                                    pToken, nLen );
 }
 
 sal_Int32 FastSaxParserImpl::GetTokenWithPrefix( const sal_Char*pPrefix, int nPrefixLen, const sal_Char* pName, int nNameLen ) throw (SAXException)
diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx
index 9d03772..45887b5 100644
--- a/sax/source/tools/fastattribs.cxx
+++ b/sax/source/tools/fastattribs.cxx
@@ -127,9 +127,10 @@ sal_Int32 FastAttributeList::getValueToken( ::sal_Int32 Token ) throw (SAXExcept
 {
     for (size_t i = 0; i < maAttributeTokens.size(); ++i)
         if (maAttributeTokens[i] == Token)
-            return maTokenLookup.getTokenFromChars( mxTokenHandler, mpTokenHandler,
-                                                    mpChunk + maAttributeValues[ i ],
-                                                    AttributeValueLength( i ) );
+            return FastTokenHandlerBase::getTokenFromChars(
+                       mxTokenHandler, mpTokenHandler,
+                       mpChunk + maAttributeValues[ i ],
+                       AttributeValueLength( i ) );
 
     throw SAXException();
 }
@@ -138,9 +139,10 @@ sal_Int32 FastAttributeList::getOptionalValueToken( ::sal_Int32 Token, ::sal_Int
 {
     for (size_t i = 0; i < maAttributeTokens.size(); ++i)
         if (maAttributeTokens[i] == Token)
-            return maTokenLookup.getTokenFromChars( mxTokenHandler, mpTokenHandler,
-                                                    mpChunk + maAttributeValues[ i ],
-                                                    AttributeValueLength( i ) );
+            return FastTokenHandlerBase::getTokenFromChars(
+                       mxTokenHandler, mpTokenHandler,
+                       mpChunk + maAttributeValues[ i ],
+                       AttributeValueLength( i ) );
 
     return Default;
 }
@@ -229,16 +231,7 @@ sal_Int32 FastAttributeList::AttributeValueLength(sal_Int32 i)
     return maAttributeValues[i + 1] - maAttributeValues[i] - 1;
 }
 
-FastTokenLookup::FastTokenLookup()
-{
-    maUtf8Buffer.realloc( mnUtf8BufferSize );
-}
-
-/**
- * Avoid doing any memory allocation if we can, instead keep a
- * pet sequence around and do some heavy petting on it.
- */
-sal_Int32 FastTokenLookup::getTokenFromChars(
+sal_Int32 FastTokenHandlerBase::getTokenFromChars(
         const css::uno::Reference< css::xml::sax::XFastTokenHandler > &xTokenHandler,
         FastTokenHandlerBase *pTokenHandler,
         const char *pToken, size_t nLen /* = 0 */ )


More information about the Libreoffice-commits mailing list