sax/source/tools/fastserializer.cxx | 21 +++++++++++++-------- sax/source/tools/fastserializer.hxx | 4 +++- 2 files changed, 16 insertions(+), 9 deletions(-)
New commits: commit 06a91dc84acdc75b77d6f73dd6cecdd5dd4d2d8b Author: Caolán McNamara <[email protected]> AuthorDate: Wed Feb 5 14:20:59 2025 +0000 Commit: Miklos Vajna <[email protected]> CommitDate: Thu Feb 6 13:02:05 2025 +0100 realloc-ing to 0 is common which frees, we can use a std::vector for this temp storage and avoid the reallocation churn. Change-Id: If7ea4ecb1e6c6a13934b5b9cc59fbb6c80180a42 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181184 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx index a5769333cc73..48552e91c723 100644 --- a/sax/source/tools/fastserializer.cxx +++ b/sax/source/tools/fastserializer.cxx @@ -714,8 +714,8 @@ namespace sax_fastparser { Int8Sequence& FastSaxSerializer::ForMerge::getData() { - merge( maData, maPostponed, true ); - maPostponed.realloc( 0 ); + merge( maData, maPostponed.data(), maPostponed.size(), true ); + maPostponed.resize(0); return maData; } @@ -730,7 +730,7 @@ namespace sax_fastparser { } std::cerr << " Postponed: "; - for ( sal_Int32 i=0, len=maPostponed.getLength(); i < len; i++ ) + for ( sal_Int32 i=0, len=maPostponed.size(); i < len; i++ ) { std::cerr << maPostponed[i]; } @@ -751,12 +751,12 @@ namespace sax_fastparser { void FastSaxSerializer::ForMerge::postpone( const Int8Sequence &rWhat ) { - merge( maPostponed, rWhat, true ); + const sal_Int8* pData = rWhat.getConstArray(); + maPostponed.insert(maPostponed.end(), pData, pData + rWhat.getLength()); } - void FastSaxSerializer::ForMerge::merge( Int8Sequence &rTop, const Int8Sequence &rMerge, bool bAppend ) + void FastSaxSerializer::ForMerge::merge(Int8Sequence &rTop, const sal_Int8* pMerge, sal_Int32 nMergeLen, bool bAppend) { - sal_Int32 nMergeLen = rMerge.getLength(); if ( nMergeLen <= 0 ) return; @@ -766,16 +766,21 @@ namespace sax_fastparser { if ( bAppend ) { // append the rMerge to the rTop - memcpy( rTop.getArray() + nTopLen, rMerge.getConstArray(), nMergeLen ); + memcpy( rTop.getArray() + nTopLen, pMerge, nMergeLen ); } else { // prepend the rMerge to the rTop memmove( rTop.getArray() + nMergeLen, rTop.getConstArray(), nTopLen ); - memcpy( rTop.getArray(), rMerge.getConstArray(), nMergeLen ); + memcpy( rTop.getArray(), pMerge, nMergeLen ); } } + void FastSaxSerializer::ForMerge::merge( Int8Sequence &rTop, const Int8Sequence &rMerge, bool bAppend ) + { + merge(rTop, rMerge.getConstArray(), rMerge.getLength(), bAppend); + } + void FastSaxSerializer::ForMerge::resetData( ) { maData = Int8Sequence(); diff --git a/sax/source/tools/fastserializer.hxx b/sax/source/tools/fastserializer.hxx index 3ed38d59b91c..fc5d6c838717 100644 --- a/sax/source/tools/fastserializer.hxx +++ b/sax/source/tools/fastserializer.hxx @@ -166,7 +166,7 @@ private: class ForMerge : public ForMergeBase { Int8Sequence maData; - Int8Sequence maPostponed; + std::vector<sal_Int8> maPostponed; public: sal_Int32 const m_Tag; @@ -194,6 +194,8 @@ private: protected: void resetData( ); static void merge( Int8Sequence &rTop, const Int8Sequence &rMerge, bool bAppend ); + private: + static void merge( Int8Sequence &rTop, const sal_Int8* pMerge, sal_Int32 nMergeLen, bool bAppend ); }; class ForSort : public ForMerge
