summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2024-07-29 20:53:07 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-07-30 12:30:07 +0200
commit24a0ecfc9c8d76dc2af6a44212d5a0a6ed6ffe6b (patch)
tree7067dc4661e036a9a90f996f040308345eea2127 /editeng
parent159d823c7b7502ee07d897d74c4e74c6e1873596 (diff)
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.grandin@collabora.co.uk>
Diffstat (limited to 'editeng')
-rw-r--r--editeng/source/editeng/impedit2.cxx8
1 files changed, 7 insertions, 1 deletions
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 ...