diff options
author | Matúš Kukan <matus.kukan@collabora.com> | 2014-09-27 21:46:36 +0200 |
---|---|---|
committer | Matúš Kukan <matus.kukan@collabora.com> | 2014-10-23 11:53:18 +0200 |
commit | 50d2ffd2a107ae8fd5c3e53f4f75234ad37081ea (patch) | |
tree | 605ca6436b643779c59992c02d9bfdc4e335c42c /sax | |
parent | e1c503a2e3309d9f738d7f702a562509899fdb3f (diff) |
FastSerializer: Use FastAttributeList directly to write faster.
Change-Id: I28085d4e060bcf052e6aa97a0822a4d653d7c066
Diffstat (limited to 'sax')
-rw-r--r-- | sax/source/tools/fastattribs.cxx | 14 | ||||
-rw-r--r-- | sax/source/tools/fastserializer.cxx | 42 | ||||
-rw-r--r-- | sax/source/tools/fastserializer.hxx | 19 | ||||
-rw-r--r-- | sax/source/tools/fshelper.cxx | 30 |
4 files changed, 42 insertions, 63 deletions
diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx index 45887b5754aa..67f3196b12c9 100644 --- a/sax/source/tools/fastattribs.cxx +++ b/sax/source/tools/fastattribs.cxx @@ -129,7 +129,7 @@ sal_Int32 FastAttributeList::getValueToken( ::sal_Int32 Token ) throw (SAXExcept if (maAttributeTokens[i] == Token) return FastTokenHandlerBase::getTokenFromChars( mxTokenHandler, mpTokenHandler, - mpChunk + maAttributeValues[ i ], + getFastAttributeValue(i), AttributeValueLength( i ) ); throw SAXException(); @@ -141,7 +141,7 @@ sal_Int32 FastAttributeList::getOptionalValueToken( ::sal_Int32 Token, ::sal_Int if (maAttributeTokens[i] == Token) return FastTokenHandlerBase::getTokenFromChars( mxTokenHandler, mpTokenHandler, - mpChunk + maAttributeValues[ i ], + getFastAttributeValue(i), AttributeValueLength( i ) ); return Default; @@ -154,7 +154,7 @@ bool FastAttributeList::getAsInteger( sal_Int32 nToken, sal_Int32 &rInt) for (size_t i = 0; i < maAttributeTokens.size(); ++i) if (maAttributeTokens[i] == nToken) { - rInt = rtl_str_toInt32( mpChunk + maAttributeValues[i], 10 ); + rInt = rtl_str_toInt32( getFastAttributeValue(i), 10 ); return true; } return false; @@ -166,7 +166,7 @@ bool FastAttributeList::getAsDouble( sal_Int32 nToken, double &rDouble) for (size_t i = 0; i < maAttributeTokens.size(); ++i) if (maAttributeTokens[i] == nToken) { - rDouble = rtl_str_toDouble( mpChunk + maAttributeValues[i] ); + rDouble = rtl_str_toDouble( getFastAttributeValue(i) ); return true; } return false; @@ -191,7 +191,7 @@ OUString FastAttributeList::getValue( ::sal_Int32 Token ) throw (SAXException, R { for (size_t i = 0; i < maAttributeTokens.size(); ++i) if (maAttributeTokens[i] == Token) - return OUString( mpChunk + maAttributeValues[i], AttributeValueLength(i), RTL_TEXTENCODING_UTF8 ); + return OUString( getFastAttributeValue(i), AttributeValueLength(i), RTL_TEXTENCODING_UTF8 ); throw SAXException(); } @@ -200,7 +200,7 @@ OUString FastAttributeList::getOptionalValue( ::sal_Int32 Token ) throw (Runtime { for (size_t i = 0; i < maAttributeTokens.size(); ++i) if (maAttributeTokens[i] == Token) - return OUString( mpChunk + maAttributeValues[i], AttributeValueLength(i), RTL_TEXTENCODING_UTF8 ); + return OUString( getFastAttributeValue(i), AttributeValueLength(i), RTL_TEXTENCODING_UTF8 ); return OUString(); } @@ -219,7 +219,7 @@ Sequence< FastAttribute > FastAttributeList::getFastAttributes( ) throw (Runtim for (size_t i = 0; i < maAttributeTokens.size(); ++i) { pAttr->Token = maAttributeTokens[i]; - pAttr->Value = OUString( mpChunk + maAttributeValues[i], AttributeValueLength(i), RTL_TEXTENCODING_UTF8 ); + pAttr->Value = OUString( getFastAttributeValue(i), AttributeValueLength(i), RTL_TEXTENCODING_UTF8 ); pAttr++; } return aSeq; diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx index f2f8bc66c7b8..3a8b770c182c 100644 --- a/sax/source/tools/fastserializer.cxx +++ b/sax/source/tools/fastserializer.cxx @@ -21,7 +21,6 @@ #include <com/sun/star/xml/Attribute.hpp> #include <com/sun/star/xml/FastAttribute.hpp> -#include <com/sun/star/xml/sax/XFastAttributeList.hpp> #include <rtl/ustrbuf.hxx> #include <comphelper/sequenceasvector.hxx> @@ -40,7 +39,6 @@ using ::com::sun::star::uno::Sequence; using ::com::sun::star::xml::FastAttribute; using ::com::sun::star::xml::Attribute; using ::com::sun::star::xml::sax::SAXException; -using ::com::sun::star::xml::sax::XFastAttributeList; using ::com::sun::star::io::XOutputStream; using ::com::sun::star::io::NotConnectedException; using ::com::sun::star::io::IOException; @@ -145,7 +143,7 @@ namespace sax_fastparser { } #endif - void FastSaxSerializer::startFastElement( ::sal_Int32 Element, const Reference< XFastAttributeList >& Attribs ) + void FastSaxSerializer::startFastElement( ::sal_Int32 Element, FastAttributeList* pAttrList ) { if ( !maMarkStack.empty() ) maMarkStack.top()->setCurrentElement( Element ); @@ -157,7 +155,7 @@ namespace sax_fastparser { writeBytes(sOpeningBracket, N_CHARS(sOpeningBracket)); writeId(Element); - writeFastAttributeList(Attribs); + writeFastAttributeList(pAttrList); writeBytes(sClosingBracket, N_CHARS(sClosingBracket)); } @@ -178,7 +176,7 @@ namespace sax_fastparser { writeBytes(sClosingBracket, N_CHARS(sClosingBracket)); } - void FastSaxSerializer::singleFastElement( ::sal_Int32 Element, const Reference< XFastAttributeList >& Attribs ) + void FastSaxSerializer::singleFastElement( ::sal_Int32 Element, FastAttributeList* pAttrList ) { if ( !maMarkStack.empty() ) maMarkStack.top()->setCurrentElement( Element ); @@ -186,7 +184,7 @@ namespace sax_fastparser { writeBytes(sOpeningBracket, N_CHARS(sOpeningBracket)); writeId(Element); - writeFastAttributeList(Attribs); + writeFastAttributeList(pAttrList); writeBytes(sSlashAndClosingBracket, N_CHARS(sSlashAndClosingBracket)); } @@ -200,38 +198,18 @@ namespace sax_fastparser { { mxFastTokenHandler = xFastTokenHandler; } - void FastSaxSerializer::writeFastAttributeList( const Reference< XFastAttributeList >& Attribs ) + + void FastSaxSerializer::writeFastAttributeList( FastAttributeList* pAttrList ) { #ifdef DBG_UTIL ::std::set<OUString> DebugAttributes; #endif - Sequence< Attribute > aAttrSeq = Attribs->getUnknownAttributes(); - const Attribute *pAttr = aAttrSeq.getConstArray(); - sal_Int32 nAttrLength = aAttrSeq.getLength(); - for (sal_Int32 i = 0; i < nAttrLength; i++) - { - writeBytes(sSpace, N_CHARS(sSpace)); - - OUString const& rAttrName(pAttr[i].Name); -#ifdef DBG_UTIL - // Well-formedness constraint: Unique Att Spec - assert(DebugAttributes.find(rAttrName) == DebugAttributes.end()); - DebugAttributes.insert(rAttrName); -#endif - write(rAttrName); - writeBytes(sEqualSignAndQuote, N_CHARS(sEqualSignAndQuote)); - write(pAttr[i].Value, true); - writeBytes(sQuote, N_CHARS(sQuote)); - } - - Sequence< FastAttribute > aFastAttrSeq = Attribs->getFastAttributes(); - const FastAttribute *pFastAttr = aFastAttrSeq.getConstArray(); - sal_Int32 nFastAttrLength = aFastAttrSeq.getLength(); - for (sal_Int32 j = 0; j < nFastAttrLength; j++) + const std::vector< sal_Int32 >& Tokens = pAttrList->getFastAttributeTokens(); + for (size_t j = 0; j < Tokens.size(); j++) { writeBytes(sSpace, N_CHARS(sSpace)); - sal_Int32 nToken = pFastAttr[j].Token; + sal_Int32 nToken = Tokens[j]; writeId(nToken); #ifdef DBG_UTIL @@ -244,7 +222,7 @@ namespace sax_fastparser { writeBytes(sEqualSignAndQuote, N_CHARS(sEqualSignAndQuote)); - write(pFastAttr[j].Value, true); + write(pAttrList->getFastAttributeValue(j), true); writeBytes(sQuote, N_CHARS(sQuote)); } diff --git a/sax/source/tools/fastserializer.hxx b/sax/source/tools/fastserializer.hxx index 82e9eeaddb01..089348a004e9 100644 --- a/sax/source/tools/fastserializer.hxx +++ b/sax/source/tools/fastserializer.hxx @@ -22,16 +22,15 @@ #include <com/sun/star/xml/sax/XFastTokenHandler.hpp> #include <com/sun/star/io/XOutputStream.hpp> -#include <rtl/byteseq.hxx> + +#include <comphelper/seqstream.hxx> +#include <sax/fastattribs.hxx> +#include <sax/fshelper.hxx> #include <stack> #include <map> - #include <boost/shared_ptr.hpp> -#include <comphelper/seqstream.hxx> -#include "sax/fshelper.hxx" - namespace sax_fastparser { /// Receives notification of sax document events to write into an XOutputStream. @@ -67,11 +66,11 @@ public: <b>or</b> operation. @param Attribs - Contains a <type>XFastAttrbitueList</type> to access the attributes + Contains a <type>FastAttributeList</type> to access the attributes from the element. */ - void startFastElement( ::sal_Int32 Element, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ); + void startFastElement( ::sal_Int32 Element, FastAttributeList* Attribs ); /** receives notification of the end of an known element. @see startFastElement @@ -91,11 +90,11 @@ public: <b>or</b> operation. @param Attribs - Contains a <type>XFastAttrbitueList</type> to access the attributes + Contains a <type>FastAttributeList</type> to access the attributes from the element. */ - void singleFastElement( ::sal_Int32 Element, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ); + void singleFastElement( ::sal_Int32 Element, FastAttributeList* Attribs ); void setOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutputStream ); void setFastTokenHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& xFastTokenHandler ); @@ -206,7 +205,7 @@ private: ::std::stack<sal_Int32> m_DebugStartedElements; #endif - void writeFastAttributeList( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ); + void writeFastAttributeList( FastAttributeList* pAttrList ); /// Write to maOutputData and if it's big enough flush that to mxOutputStream void writeOutput( const sal_Int8* pStr, size_t nLen ); void writeOutput( const css::uno::Sequence< ::sal_Int8 >& aData ); diff --git a/sax/source/tools/fshelper.cxx b/sax/source/tools/fshelper.cxx index 0e5df2819378..30e59322f034 100644 --- a/sax/source/tools/fshelper.cxx +++ b/sax/source/tools/fshelper.cxx @@ -20,6 +20,7 @@ #include <sax/fshelper.hxx> #include "fastserializer.hxx" #include <com/sun/star/xml/sax/FastTokenHandler.hpp> +#include <com/sun/star/xml/sax/XFastTokenHandler.hpp> #include <comphelper/processfactory.hxx> #include <rtl/ustrbuf.hxx> @@ -30,11 +31,10 @@ namespace sax_fastparser { FastSerializerHelper::FastSerializerHelper(const Reference< io::XOutputStream >& xOutputStream, bool bWriteHeader ) : mpSerializer(new FastSaxSerializer()) + , maAttrList(Reference< xml::sax::XFastTokenHandler >()) { Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext(), UNO_SET_THROW ); - mxTokenHandler = css::xml::sax::FastTokenHandler::create(xContext); - - mpSerializer->setFastTokenHandler( mxTokenHandler ); + mpSerializer->setFastTokenHandler( css::xml::sax::FastTokenHandler::create(xContext) ); assert(xOutputStream.is()); // cannot do anything without that mpSerializer->setOutputStream( xOutputStream ); if( bWriteHeader ) @@ -51,7 +51,7 @@ void FastSerializerHelper::startElementInternal(sal_Int32 elementTokenId, ...) { va_list args; va_start( args, elementTokenId ); - FastAttributeList* pAttrList = new FastAttributeList( mxTokenHandler ); + maAttrList.clear(); while (true) { @@ -60,11 +60,10 @@ void FastSerializerHelper::startElementInternal(sal_Int32 elementTokenId, ...) break; const char* pValue = va_arg(args, const char*); if (pValue) - pAttrList->add(nName, pValue); + maAttrList.add(nName, pValue); } - const com::sun::star::uno::Reference<com::sun::star::xml::sax::XFastAttributeList> xAttrList(pAttrList); - mpSerializer->startFastElement(elementTokenId, xAttrList); + mpSerializer->startFastElement(elementTokenId, &maAttrList); va_end( args ); } @@ -72,7 +71,7 @@ void FastSerializerHelper::singleElementInternal(sal_Int32 elementTokenId, ...) { va_list args; va_start( args, elementTokenId ); - FastAttributeList* pAttrList = new FastAttributeList( mxTokenHandler ); + maAttrList.clear(); while (true) { @@ -81,11 +80,10 @@ void FastSerializerHelper::singleElementInternal(sal_Int32 elementTokenId, ...) break; const char* pValue = va_arg(args, const char*); if (pValue) - pAttrList->add(nName, pValue); + maAttrList.add(nName, pValue); } - const com::sun::star::uno::Reference<com::sun::star::xml::sax::XFastAttributeList> xAttrList(pAttrList); - mpSerializer->singleFastElement(elementTokenId, xAttrList); + mpSerializer->singleFastElement(elementTokenId, &maAttrList); va_end( args ); } @@ -96,13 +94,17 @@ void FastSerializerHelper::endElement(sal_Int32 elementTokenId) void FastSerializerHelper::startElement(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList) { - mpSerializer->startFastElement(elementTokenId, xAttrList); + FastAttributeList* pAttrList = dynamic_cast< FastAttributeList* >(xAttrList.get()); + assert(pAttrList); + mpSerializer->startFastElement(elementTokenId, pAttrList); } void FastSerializerHelper::singleElement(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList) { - mpSerializer->singleFastElement(elementTokenId, xAttrList); + FastAttributeList* pAttrList = dynamic_cast< FastAttributeList* >(xAttrList.get()); + assert(pAttrList); + mpSerializer->singleFastElement(elementTokenId, pAttrList); } FastSerializerHelper* FastSerializerHelper::write(const char* value) @@ -172,7 +174,7 @@ void FastSerializerHelper::mergeTopMarks( MergeMarksEnum eMergeType ) FastAttributeList * FastSerializerHelper::createAttrList() { - return new FastAttributeList( mxTokenHandler ); + return new FastAttributeList( Reference< xml::sax::XFastTokenHandler >() ); } |