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

Michael Meeks michael.meeks at collabora.com
Wed Nov 20 04:13:12 PST 2013


 include/oox/helper/attributelist.hxx               |    6 ++++
 include/sax/fastattribs.hxx                        |    4 +++
 offapi/com/sun/star/xml/sax/XFastAttributeList.idl |    8 +++---
 oox/source/helper/attributelist.cxx                |   27 +++++++++++++++------
 sax/source/tools/fastattribs.cxx                   |   25 +++++++++++++++++++
 sc/source/filter/oox/sheetdatacontext.cxx          |    2 -
 6 files changed, 60 insertions(+), 12 deletions(-)

New commits:
commit 9491ca3f64bd44a6a8e63f7d2eae02164f792258
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Wed Nov 20 12:11:44 2013 +0000

    fastparser: avoid excessive alloc/frees for int / bool / double parsing
    
    Change-Id: I596bbc723558f04588d9e767d64732164524e57a

diff --git a/include/oox/helper/attributelist.hxx b/include/oox/helper/attributelist.hxx
index 3fb6e8d..6aa035a 100644
--- a/include/oox/helper/attributelist.hxx
+++ b/include/oox/helper/attributelist.hxx
@@ -27,6 +27,10 @@
 #include <oox/token/tokens.hxx>
 #include <oox/dllapi.h>
 
+namespace sax_fastparser {
+    class FastAttributeList;
+};
+
 namespace oox {
 
 // ============================================================================
@@ -159,6 +163,8 @@ public:
 private:
     ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >
                         mxAttribs;
+    mutable sax_fastparser::FastAttributeList *mpAttribList;
+    sax_fastparser::FastAttributeList *getAttribList() const;
 };
 
 // ============================================================================
diff --git a/include/sax/fastattribs.hxx b/include/sax/fastattribs.hxx
index c780603..fd87a94 100644
--- a/include/sax/fastattribs.hxx
+++ b/include/sax/fastattribs.hxx
@@ -73,6 +73,10 @@ public:
     void addUnknown( const OUString& rNamespaceURL, const OString& rName, const sal_Char* pValue );
     void addUnknown( const OString& rName, const sal_Char* pValue );
 
+    // performance sensitive shortcuts to avoid allocation ...
+    bool getAsInteger( sal_Int32 nToken, sal_Int32 &rInt);
+    bool getAsDouble( sal_Int32 nToken, double &rDouble);
+
     // XFastAttributeList
     virtual ::sal_Bool SAL_CALL hasAttribute( ::sal_Int32 Token ) throw (::com::sun::star::uno::RuntimeException);
     virtual ::sal_Int32 SAL_CALL getValueToken( ::sal_Int32 Token ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
diff --git a/offapi/com/sun/star/xml/sax/XFastAttributeList.idl b/offapi/com/sun/star/xml/sax/XFastAttributeList.idl
index 509bcf8..840fc92 100644
--- a/offapi/com/sun/star/xml/sax/XFastAttributeList.idl
+++ b/offapi/com/sun/star/xml/sax/XFastAttributeList.idl
@@ -56,7 +56,7 @@ interface XFastAttributeList: com::sun::star::uno::XInterface
     */
     boolean hasAttribute( [in] long Token );
 
-    /** retrieves the token of an attributes value.<br>
+    /** retrieves the token of an attribute value.<br>
 
         @param Token
             contains the integer token from the XFastTokenHandler
@@ -78,7 +78,7 @@ interface XFastAttributeList: com::sun::star::uno::XInterface
     long getValueToken( [in] long Token )
         raises( SAXException );
 
-    /**retrieves the token of an attributes value.<br>
+    /**retrieves the token of an attribute value.<br>
 
         @param Token
             contains the integer token from the XFastTokenHandler
@@ -101,7 +101,7 @@ interface XFastAttributeList: com::sun::star::uno::XInterface
     */
     long getOptionalValueToken( [in] long Token, [in] long Default );
 
-    /** retrieves the value of an attributes.<br>
+    /** retrieves the value of an attribute.<br>
 
         @param Token
             contains the integer token from the XFastTokenHandler
@@ -123,7 +123,7 @@ interface XFastAttributeList: com::sun::star::uno::XInterface
     string getValue( [in] long Token )
         raises( SAXException );
 
-    /** retrieves the value of an attributes.<br>
+    /** retrieves the value of an attribute.<br>
 
         @param Token
             contains the integer token from the XFastTokenHandler
diff --git a/oox/source/helper/attributelist.cxx b/oox/source/helper/attributelist.cxx
index 2c0eb23..7c41d8e 100644
--- a/oox/source/helper/attributelist.cxx
+++ b/oox/source/helper/attributelist.cxx
@@ -19,8 +19,10 @@
 
 #include "oox/helper/attributelist.hxx"
 
+#include <cassert>
 #include <osl/diagnose.h>
 #include <rtl/ustrbuf.hxx>
+#include <sax/fastattribs.hxx>
 #include "oox/token/tokenmap.hxx"
 
 namespace oox {
@@ -117,11 +119,22 @@ sal_Int32 AttributeConversion::decodeIntegerHex( const OUString& rValue )
 // ============================================================================
 
 AttributeList::AttributeList( const Reference< XFastAttributeList >& rxAttribs ) :
-    mxAttribs( rxAttribs )
+    mxAttribs( rxAttribs ),
+    mpAttribList( NULL )
 {
     OSL_ENSURE( mxAttribs.is(), "AttributeList::AttributeList - missing attribute list interface" );
 }
 
+sax_fastparser::FastAttributeList *AttributeList::getAttribList() const
+{
+    if( mpAttribList == NULL )
+    {
+        assert( dynamic_cast< sax_fastparser::FastAttributeList *>( mxAttribs.get() ) != NULL );
+        mpAttribList = static_cast< sax_fastparser::FastAttributeList *>( mxAttribs.get() );
+    }
+    return mpAttribList;
+}
+
 bool AttributeList::hasAttribute( sal_Int32 nAttrToken ) const
 {
     return mxAttribs->hasAttribute( nAttrToken );
@@ -153,16 +166,16 @@ OptValue< OUString > AttributeList::getXString( sal_Int32 nAttrToken ) const
 
 OptValue< double > AttributeList::getDouble( sal_Int32 nAttrToken ) const
 {
-    OUString aValue = mxAttribs->getOptionalValue( nAttrToken );
-    bool bValid = !aValue.isEmpty();
-    return OptValue< double >( bValid, bValid ? AttributeConversion::decodeDouble( aValue ) : 0.0 );
+    double nValue;
+    bool bValid = getAttribList()->getAsDouble( nAttrToken, nValue );
+    return OptValue< double >( bValid, nValue );
 }
 
 OptValue< sal_Int32 > AttributeList::getInteger( sal_Int32 nAttrToken ) const
 {
-    OUString aValue = mxAttribs->getOptionalValue( nAttrToken );
-    bool bValid = !aValue.isEmpty();
-    return OptValue< sal_Int32 >( bValid, bValid ? AttributeConversion::decodeInteger( aValue ) : 0 );
+    sal_Int32 nValue;
+    bool bValid = getAttribList()->getAsInteger( nAttrToken, nValue );
+    return OptValue< sal_Int32 >( bValid, nValue );
 }
 
 OptValue< sal_uInt32 > AttributeList::getUnsigned( sal_Int32 nAttrToken ) const
diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx
index 2297b1d..1705c30 100644
--- a/sax/source/tools/fastattribs.cxx
+++ b/sax/source/tools/fastattribs.cxx
@@ -132,6 +132,31 @@ sal_Int32 FastAttributeList::getOptionalValueToken( ::sal_Int32 Token, ::sal_Int
     return Default;
 }
 
+// performance sensitive shortcuts to avoid allocation ...
+bool FastAttributeList::getAsInteger( sal_Int32 nToken, sal_Int32 &rInt)
+{
+    rInt = 0;
+    for (size_t i = 0; i < maAttributeTokens.size(); ++i)
+        if (maAttributeTokens[i] == nToken)
+        {
+            rInt = rtl_str_toInt32( mpChunk + maAttributeValues[i], 10 );
+            return true;
+        }
+    return false;
+}
+
+bool FastAttributeList::getAsDouble( sal_Int32 nToken, double &rDouble)
+{
+    rDouble = 0.0;
+    for (size_t i = 0; i < maAttributeTokens.size(); ++i)
+        if (maAttributeTokens[i] == nToken)
+        {
+            rDouble = rtl_str_toDouble( mpChunk + maAttributeValues[i] );
+            return true;
+        }
+    return false;
+}
+
 OUString FastAttributeList::getValue( ::sal_Int32 Token ) throw (SAXException, RuntimeException)
 {
     for (size_t i = 0; i < maAttributeTokens.size(); ++i)
diff --git a/sc/source/filter/oox/sheetdatacontext.cxx b/sc/source/filter/oox/sheetdatacontext.cxx
index 1a1d574..da234c1 100644
--- a/sc/source/filter/oox/sheetdatacontext.cxx
+++ b/sc/source/filter/oox/sheetdatacontext.cxx
@@ -310,7 +310,7 @@ void SheetDataContext::importRow( const AttributeList& rAttribs )
 
 bool SheetDataContext::importCell( const AttributeList& rAttribs )
 {
-    OUString aCellAddrStr =  rAttribs.getString( XML_r, OUString() );
+    OUString aCellAddrStr = rAttribs.getString( XML_r, OUString() );
     bool bValid = true;
     if(aCellAddrStr.isEmpty())
     {


More information about the Libreoffice-commits mailing list