fastparser: avoid excessive alloc/frees for int / bool / double parsing
Change-Id: I596bbc723558f04588d9e767d64732164524e57a
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
|
@@ -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);
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
@@ -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())
|
||||
{
|
||||
|
Reference in New Issue
Block a user