diff options
-rw-r--r-- | include/sax/fastattribs.hxx | 20 | ||||
-rw-r--r-- | sax/source/fastparser/fastparser.cxx | 8 | ||||
-rw-r--r-- | sax/source/tools/fastattribs.cxx | 57 |
3 files changed, 60 insertions, 25 deletions
diff --git a/include/sax/fastattribs.hxx b/include/sax/fastattribs.hxx index 88e9d615e56e..238b7d4297f8 100644 --- a/include/sax/fastattribs.hxx +++ b/include/sax/fastattribs.hxx @@ -40,9 +40,9 @@ struct UnknownAttribute OString maName; OString maValue; - UnknownAttribute( const OUString& rNamespaceURL, const OString& rName, const OString& rValue ); + UnknownAttribute( const OUString& rNamespaceURL, const OString& rName, const sal_Char* pValue ); - UnknownAttribute( const OString& rName, const OString& rValue ); + UnknownAttribute( const OString& rName, const sal_Char* pValue ); void FillAttribute( ::com::sun::star::xml::Attribute* pAttrib ) const; }; @@ -56,9 +56,10 @@ public: virtual ~FastAttributeList(); void clear(); + void add( sal_Int32 nToken, const sal_Char* pValue, size_t nValueLength = 0 ); void add( sal_Int32 nToken, const OString& rValue ); - void addUnknown( const OUString& rNamespaceURL, const OString& rName, const OString& rValue ); - void addUnknown( const OString& rName, const OString& rValue ); + void addUnknown( const OUString& rNamespaceURL, const OString& rName, const sal_Char* pValue ); + void addUnknown( const OString& rName, const sal_Char* pValue ); // XFastAttributeList virtual ::sal_Bool SAL_CALL hasAttribute( ::sal_Int32 Token ) throw (::com::sun::star::uno::RuntimeException); @@ -70,11 +71,18 @@ public: virtual ::com::sun::star::uno::Sequence< ::com::sun::star::xml::FastAttribute > SAL_CALL getFastAttributes() throw (::com::sun::star::uno::RuntimeException); private: + inline sal_Int32 AttributeValueLength(sal_Int32 i); + +private: + sal_Char *mpChunk; ///< buffer to store all attribute values - null terminated strings + sal_Int32 mnChunkLength; ///< size of allocated memory for mpChunk + // maAttributeValues stores pointers, relative to mpChunk, for each attribute value string + // length of the string is maAttributeValues[n+1] - maAttributeValues[n] - 1 + // maAttributeValues[0] == 0 + std::vector< sal_Int32 > maAttributeValues; std::vector< sal_Int32 > maAttributeTokens; - std::vector< OString > maAttributeValues; UnknownAttributeList maUnknownAttributes; ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler > mxTokenHandler; - }; } 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: */ |