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/token/tokens.hxx>
|
||||||
#include <oox/dllapi.h>
|
#include <oox/dllapi.h>
|
||||||
|
|
||||||
|
namespace sax_fastparser {
|
||||||
|
class FastAttributeList;
|
||||||
|
};
|
||||||
|
|
||||||
namespace oox {
|
namespace oox {
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -159,6 +163,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >
|
::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >
|
||||||
mxAttribs;
|
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 OUString& rNamespaceURL, const OString& rName, const sal_Char* pValue );
|
||||||
void addUnknown( 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
|
// XFastAttributeList
|
||||||
virtual ::sal_Bool SAL_CALL hasAttribute( ::sal_Int32 Token ) throw (::com::sun::star::uno::RuntimeException);
|
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);
|
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 );
|
boolean hasAttribute( [in] long Token );
|
||||||
|
|
||||||
/** retrieves the token of an attributes value.<br>
|
/** retrieves the token of an attribute value.<br>
|
||||||
|
|
||||||
@param Token
|
@param Token
|
||||||
contains the integer token from the XFastTokenHandler
|
contains the integer token from the XFastTokenHandler
|
||||||
@@ -78,7 +78,7 @@ interface XFastAttributeList: com::sun::star::uno::XInterface
|
|||||||
long getValueToken( [in] long Token )
|
long getValueToken( [in] long Token )
|
||||||
raises( SAXException );
|
raises( SAXException );
|
||||||
|
|
||||||
/**retrieves the token of an attributes value.<br>
|
/**retrieves the token of an attribute value.<br>
|
||||||
|
|
||||||
@param Token
|
@param Token
|
||||||
contains the integer token from the XFastTokenHandler
|
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 );
|
long getOptionalValueToken( [in] long Token, [in] long Default );
|
||||||
|
|
||||||
/** retrieves the value of an attributes.<br>
|
/** retrieves the value of an attribute.<br>
|
||||||
|
|
||||||
@param Token
|
@param Token
|
||||||
contains the integer token from the XFastTokenHandler
|
contains the integer token from the XFastTokenHandler
|
||||||
@@ -123,7 +123,7 @@ interface XFastAttributeList: com::sun::star::uno::XInterface
|
|||||||
string getValue( [in] long Token )
|
string getValue( [in] long Token )
|
||||||
raises( SAXException );
|
raises( SAXException );
|
||||||
|
|
||||||
/** retrieves the value of an attributes.<br>
|
/** retrieves the value of an attribute.<br>
|
||||||
|
|
||||||
@param Token
|
@param Token
|
||||||
contains the integer token from the XFastTokenHandler
|
contains the integer token from the XFastTokenHandler
|
||||||
|
@@ -19,8 +19,10 @@
|
|||||||
|
|
||||||
#include "oox/helper/attributelist.hxx"
|
#include "oox/helper/attributelist.hxx"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <osl/diagnose.h>
|
#include <osl/diagnose.h>
|
||||||
#include <rtl/ustrbuf.hxx>
|
#include <rtl/ustrbuf.hxx>
|
||||||
|
#include <sax/fastattribs.hxx>
|
||||||
#include "oox/token/tokenmap.hxx"
|
#include "oox/token/tokenmap.hxx"
|
||||||
|
|
||||||
namespace oox {
|
namespace oox {
|
||||||
@@ -117,11 +119,22 @@ sal_Int32 AttributeConversion::decodeIntegerHex( const OUString& rValue )
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
AttributeList::AttributeList( const Reference< XFastAttributeList >& rxAttribs ) :
|
AttributeList::AttributeList( const Reference< XFastAttributeList >& rxAttribs ) :
|
||||||
mxAttribs( rxAttribs )
|
mxAttribs( rxAttribs ),
|
||||||
|
mpAttribList( NULL )
|
||||||
{
|
{
|
||||||
OSL_ENSURE( mxAttribs.is(), "AttributeList::AttributeList - missing attribute list interface" );
|
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
|
bool AttributeList::hasAttribute( sal_Int32 nAttrToken ) const
|
||||||
{
|
{
|
||||||
return mxAttribs->hasAttribute( nAttrToken );
|
return mxAttribs->hasAttribute( nAttrToken );
|
||||||
@@ -153,16 +166,16 @@ OptValue< OUString > AttributeList::getXString( sal_Int32 nAttrToken ) const
|
|||||||
|
|
||||||
OptValue< double > AttributeList::getDouble( sal_Int32 nAttrToken ) const
|
OptValue< double > AttributeList::getDouble( sal_Int32 nAttrToken ) const
|
||||||
{
|
{
|
||||||
OUString aValue = mxAttribs->getOptionalValue( nAttrToken );
|
double nValue;
|
||||||
bool bValid = !aValue.isEmpty();
|
bool bValid = getAttribList()->getAsDouble( nAttrToken, nValue );
|
||||||
return OptValue< double >( bValid, bValid ? AttributeConversion::decodeDouble( aValue ) : 0.0 );
|
return OptValue< double >( bValid, nValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
OptValue< sal_Int32 > AttributeList::getInteger( sal_Int32 nAttrToken ) const
|
OptValue< sal_Int32 > AttributeList::getInteger( sal_Int32 nAttrToken ) const
|
||||||
{
|
{
|
||||||
OUString aValue = mxAttribs->getOptionalValue( nAttrToken );
|
sal_Int32 nValue;
|
||||||
bool bValid = !aValue.isEmpty();
|
bool bValid = getAttribList()->getAsInteger( nAttrToken, nValue );
|
||||||
return OptValue< sal_Int32 >( bValid, bValid ? AttributeConversion::decodeInteger( aValue ) : 0 );
|
return OptValue< sal_Int32 >( bValid, nValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
OptValue< sal_uInt32 > AttributeList::getUnsigned( sal_Int32 nAttrToken ) const
|
OptValue< sal_uInt32 > AttributeList::getUnsigned( sal_Int32 nAttrToken ) const
|
||||||
|
@@ -132,6 +132,31 @@ sal_Int32 FastAttributeList::getOptionalValueToken( ::sal_Int32 Token, ::sal_Int
|
|||||||
return Default;
|
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)
|
OUString FastAttributeList::getValue( ::sal_Int32 Token ) throw (SAXException, RuntimeException)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < maAttributeTokens.size(); ++i)
|
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 )
|
bool SheetDataContext::importCell( const AttributeList& rAttribs )
|
||||||
{
|
{
|
||||||
OUString aCellAddrStr = rAttribs.getString( XML_r, OUString() );
|
OUString aCellAddrStr = rAttribs.getString( XML_r, OUString() );
|
||||||
bool bValid = true;
|
bool bValid = true;
|
||||||
if(aCellAddrStr.isEmpty())
|
if(aCellAddrStr.isEmpty())
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user