summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@gmail.com>2013-10-16 11:15:31 +0200
committerMatúš Kukan <matus.kukan@gmail.com>2013-10-17 21:38:37 +0200
commitc293e73e8f6802fe9733fb69616efb8074acfce7 (patch)
tree8443e7ca136bc1d5339715ce17d78e1f51a931b0 /sax
parent9ae701509add0f0192b02fab787c6acbc64be349 (diff)
FastAttributeList: avoid OStrings in attribute list; just use char buffer
Change-Id: I4879563fae3b85c68bbd1c4b260f9833848f4bda
Diffstat (limited to 'sax')
-rw-r--r--sax/source/fastparser/fastparser.cxx8
-rw-r--r--sax/source/tools/fastattribs.cxx57
2 files changed, 46 insertions, 19 deletions
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 2387d23b2b84..9a31cc852005 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -793,10 +793,10 @@ void FastSaxParser::callbackStartElement( const XML_Char* pwName, const XML_Char
{
sal_Int32 nAttributeToken = GetTokenWithPrefix( pPrefix, nPrefixLen, pName, nNameLen );
if( nAttributeToken != FastToken::DONTKNOW )
- rEntity.mxAttributes->add( nAttributeToken, OString(awAttributes[i+1]) );
+ rEntity.mxAttributes->add( nAttributeToken, awAttributes[i+1] );
else
rEntity.mxAttributes->addUnknown( GetNamespaceURL( pPrefix, nPrefixLen ),
- OString(pName, nNameLen), OString(awAttributes[i+1]) );
+ OString(pName, nNameLen), awAttributes[i+1] );
}
}
else
@@ -805,9 +805,9 @@ void FastSaxParser::callbackStartElement( const XML_Char* pwName, const XML_Char
{
sal_Int32 nAttributeToken = GetToken( pName, nNameLen );
if( nAttributeToken != FastToken::DONTKNOW )
- rEntity.mxAttributes->add( nAttributeToken, OString(awAttributes[i+1]) );
+ rEntity.mxAttributes->add( nAttributeToken, awAttributes[i+1] );
else
- rEntity.mxAttributes->addUnknown( OString(pName, nNameLen), OString(awAttributes[i+1]) );
+ rEntity.mxAttributes->addUnknown( OString(pName, nNameLen), awAttributes[i+1] );
}
}
}
diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx
index b25ff089079c..3ebab237b411 100644
--- a/sax/source/tools/fastattribs.cxx
+++ b/sax/source/tools/fastattribs.cxx
@@ -27,13 +27,13 @@ using namespace ::com::sun::star::xml::sax;
namespace sax_fastparser
{
-UnknownAttribute::UnknownAttribute( const OUString& rNamespaceURL, const OString& rName, const OString& rValue )
- : maNamespaceURL( rNamespaceURL ), maName( rName ), maValue( rValue )
+UnknownAttribute::UnknownAttribute( const OUString& rNamespaceURL, const OString& rName, const sal_Char* pValue )
+ : maNamespaceURL( rNamespaceURL ), maName( rName ), maValue( pValue )
{
}
-UnknownAttribute::UnknownAttribute( const OString& rName, const OString& rValue )
- : maName( rName ), maValue( rValue )
+UnknownAttribute::UnknownAttribute( const OString& rName, const sal_Char* pValue )
+ : maName( rName ), maValue( pValue )
{
}
@@ -50,33 +50,54 @@ void UnknownAttribute::FillAttribute( Attribute* pAttrib ) const
FastAttributeList::FastAttributeList( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& xTokenHandler )
: mxTokenHandler( xTokenHandler )
{
+ // random initial size of buffer to store attribute values
+ mnChunkLength = 58;
+ mpChunk = (sal_Char *) malloc( mnChunkLength );
+ maAttributeValues.push_back( 0 );
}
FastAttributeList::~FastAttributeList()
{
+ free( mpChunk );
}
void FastAttributeList::clear()
{
maAttributeTokens.clear();
maAttributeValues.clear();
+ maAttributeValues.push_back( 0 );
maUnknownAttributes.clear();
}
-void FastAttributeList::add( sal_Int32 nToken, const OString& rValue )
+void FastAttributeList::add( sal_Int32 nToken, const sal_Char* pValue, size_t nValueLength )
{
maAttributeTokens.push_back( nToken );
- maAttributeValues.push_back( rValue );
+ if (nValueLength == 0)
+ nValueLength = strlen(pValue);
+ sal_Int32 nWritePosition = maAttributeValues.back();
+ maAttributeValues.push_back( maAttributeValues.back() + nValueLength + 1 );
+ if (maAttributeValues.back() > mnChunkLength)
+ {
+ mnChunkLength = maAttributeValues.back();
+ mpChunk = (sal_Char *) realloc( mpChunk, mnChunkLength );
+ }
+ strncpy(mpChunk + nWritePosition, pValue, nValueLength);
+ mpChunk[nWritePosition + nValueLength] = '\0';
+}
+
+void FastAttributeList::add( sal_Int32 nToken, const OString& rValue )
+{
+ add( nToken, rValue.getStr(), rValue.getLength() );
}
-void FastAttributeList::addUnknown( const OUString& rNamespaceURL, const OString& rName, const OString& rValue )
+void FastAttributeList::addUnknown( const OUString& rNamespaceURL, const OString& rName, const sal_Char* pValue )
{
- maUnknownAttributes.push_back( UnknownAttribute( rNamespaceURL, rName, rValue ) );
+ maUnknownAttributes.push_back( UnknownAttribute( rNamespaceURL, rName, pValue ) );
}
-void FastAttributeList::addUnknown( const OString& rName, const OString& rValue )
+void FastAttributeList::addUnknown( const OString& rName, const sal_Char* pValue )
{
- maUnknownAttributes.push_back( UnknownAttribute( rName, rValue ) );
+ maUnknownAttributes.push_back( UnknownAttribute( rName, pValue ) );
}
// XFastAttributeList
@@ -94,7 +115,7 @@ sal_Int32 FastAttributeList::getValueToken( ::sal_Int32 Token ) throw (SAXExcept
for (size_t i = 0; i < maAttributeTokens.size(); ++i)
if (maAttributeTokens[i] == Token)
{
- Sequence< sal_Int8 > aSeq( (sal_Int8*) maAttributeValues[i].getStr(), maAttributeValues[i].getLength() );
+ Sequence< sal_Int8 > aSeq( (sal_Int8*) mpChunk + maAttributeValues[i], AttributeValueLength(i) );
return mxTokenHandler->getTokenFromUTF8( aSeq );
}
@@ -106,7 +127,7 @@ sal_Int32 FastAttributeList::getOptionalValueToken( ::sal_Int32 Token, ::sal_Int
for (size_t i = 0; i < maAttributeTokens.size(); ++i)
if (maAttributeTokens[i] == Token)
{
- Sequence< sal_Int8 > aSeq( (sal_Int8*) maAttributeValues[i].getStr(), maAttributeValues[i].getLength() );
+ Sequence< sal_Int8 > aSeq( (sal_Int8*) mpChunk + maAttributeValues[i], AttributeValueLength(i) );
return mxTokenHandler->getTokenFromUTF8( aSeq );
}
@@ -117,7 +138,7 @@ OUString FastAttributeList::getValue( ::sal_Int32 Token ) throw (SAXException, R
{
for (size_t i = 0; i < maAttributeTokens.size(); ++i)
if (maAttributeTokens[i] == Token)
- return OStringToOUString( maAttributeValues[i], RTL_TEXTENCODING_UTF8 );
+ return OUString( mpChunk + maAttributeValues[i], AttributeValueLength(i), RTL_TEXTENCODING_UTF8 );
throw SAXException();
}
@@ -126,7 +147,7 @@ OUString FastAttributeList::getOptionalValue( ::sal_Int32 Token ) throw (Runtime
{
for (size_t i = 0; i < maAttributeTokens.size(); ++i)
if (maAttributeTokens[i] == Token)
- return OStringToOUString( maAttributeValues[i], RTL_TEXTENCODING_UTF8 );
+ return OUString( mpChunk + maAttributeValues[i], AttributeValueLength(i), RTL_TEXTENCODING_UTF8 );
return OUString();
}
@@ -145,12 +166,18 @@ Sequence< FastAttribute > FastAttributeList::getFastAttributes( ) throw (Runtim
for (size_t i = 0; i < maAttributeTokens.size(); ++i)
{
pAttr->Token = maAttributeTokens[i];
- pAttr->Value = OStringToOUString( maAttributeValues[i], RTL_TEXTENCODING_UTF8 );
+ pAttr->Value = OUString( mpChunk + maAttributeValues[i], AttributeValueLength(i), RTL_TEXTENCODING_UTF8 );
pAttr++;
}
return aSeq;
}
+sal_Int32 FastAttributeList::AttributeValueLength(sal_Int32 i)
+{
+ // Pointers to null terminated strings
+ return maAttributeValues[i + 1] - maAttributeValues[i] - 1;
+}
+
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */