editeng/source/editeng/impedit2.cxx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
New commits: commit 24a0ecfc9c8d76dc2af6a44212d5a0a6ed6ffe6b Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Mon Jul 29 20:53:07 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Jul 30 12:30:07 2024 +0200 tdf#161846 reduce re-alloc in ImpEditEngine::GetSelected we can fairly easily allocate the exact buffer size we need and avoid needing to extend the buffer Change-Id: I7f0b2533dab03452db60ddaa5b8a5f3471c195ba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171225 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index f63a12a5bbc1..b2d4a1283cff 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -283,7 +283,13 @@ OUString ImpEditEngine::GetSelected( const EditSelection& rSel ) const OSL_ENSURE( nStartNode <= nEndNode, "Selection not sorted ?" ); - OUStringBuffer aText(256); + // calculate buffer size we need + sal_Int32 nBufSize = (aSel.Max().GetIndex() - aSel.Min().GetIndex() + 1) + + (nEndNode - nStartNode + 1); + // protect against sometimes whacky selection + if (nBufSize < 0 || nBufSize > 64 * 1024) + nBufSize = 256; + OUStringBuffer aText(nBufSize); const OUString aSep = EditDoc::GetSepStr( LINEEND_LF ); // iterate over the paragraphs ...