From b7266ddb2f580a2ed3c558d1996b5e2760023145 Mon Sep 17 00:00:00 2001 From: Matúš Kukan Date: Wed, 24 Sep 2014 14:55:02 +0200 Subject: FastSerializer: Buffer output and write it only at the end Use OSequenceOutputStream class to concatenate strings in a Sequence buffer. And write data to file only at the end. The design is a bit fragile, since all FSHelpers need to be destroyed before calling FilterBase::commitStorage(). Otherwise data is not written. Change-Id: I26b02335ef36011bfcda17484b560811d18c7657 --- sax/source/tools/fastserializer.cxx | 11 ++++++++--- sax/source/tools/fastserializer.hxx | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'sax') diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx index fbce18aa9ab0..a9520e4907ea 100644 --- a/sax/source/tools/fastserializer.cxx +++ b/sax/source/tools/fastserializer.cxx @@ -53,7 +53,9 @@ using ::com::sun::star::io::BufferSizeExceededException; namespace sax_fastparser { FastSaxSerializer::FastSaxSerializer( ) - : mxOutputStream() + : maOutputData() + , maOutputStream(maOutputData) + , mxOutputStream() , mxFastTokenHandler() , maMarkStack() , maClosingBracket((const sal_Int8 *)">", 1) @@ -112,6 +114,9 @@ namespace sax_fastparser { { if (!mxOutputStream.is()) return; + + maOutputStream.flush(); + mxOutputStream->writeBytes(maOutputData); } void SAL_CALL FastSaxSerializer::writeId( ::sal_Int32 nElement ) @@ -293,7 +298,7 @@ namespace sax_fastparser { if ( maMarkStack.size() == 1 && eMergeType != MERGE_MARKS_IGNORE) { - mxOutputStream->writeBytes( maMarkStack.top()->getData() ); + maOutputStream.writeBytes( maMarkStack.top()->getData() ); maMarkStack.pop(); return; } @@ -314,7 +319,7 @@ namespace sax_fastparser { void FastSaxSerializer::writeBytes( const Sequence< ::sal_Int8 >& aData ) throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) { if ( maMarkStack.empty() ) - mxOutputStream->writeBytes( aData ); + maOutputStream.writeBytes( aData ); else maMarkStack.top()->append( aData ); } diff --git a/sax/source/tools/fastserializer.hxx b/sax/source/tools/fastserializer.hxx index a88e3ca0e166..147d7671d160 100644 --- a/sax/source/tools/fastserializer.hxx +++ b/sax/source/tools/fastserializer.hxx @@ -29,6 +29,7 @@ #include +#include #include "sax/fshelper.hxx" namespace sax_fastparser { @@ -148,6 +149,11 @@ public: void mergeTopMarks( sax_fastparser::MergeMarksEnum eMergeType = sax_fastparser::MERGE_MARKS_APPEND ); private: + /// Buffer written to mxOutputStream at the end, called from FSHelper destructor. + css::uno::Sequence< sal_Int8 > maOutputData; + /// Helper class to dynamically allocate memory when needed for maOutputData. + comphelper::OSequenceOutputStream maOutputStream; + /// Output stream, usually writing data into files. ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > mxOutputStream; ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler > mxFastTokenHandler; -- cgit