editeng/inc/ContentNode.hxx | 2 +- editeng/inc/editdoc.hxx | 2 +- editeng/source/editeng/ContentNode.cxx | 7 +++++-- editeng/source/editeng/editdoc.cxx | 17 +++++++++-------- editeng/source/editeng/impedit2.cxx | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-)
New commits: commit 8ab44b114c6706ab2e3d8a19884daeb544d3c2e1 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Mon Jul 29 20:34:49 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Jul 30 10:39:59 2024 +0200 tdf#161846 avoid allocation in ContentNode::Insert which is fairly common Change-Id: I3b1ec65d880cb71b8894f292061e23376af177bb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171224 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/editeng/inc/ContentNode.hxx b/editeng/inc/ContentNode.hxx index 308d3ef9d1e0..6b764ccbb524 100644 --- a/editeng/inc/ContentNode.hxx +++ b/editeng/inc/ContentNode.hxx @@ -163,7 +163,7 @@ public: void UnExpandPositions(sal_Int32& rStartPos, sal_Int32& rEndPos); void SetChar(sal_Int32 nPos, sal_Unicode c); - void Insert(std::u16string_view rStr, sal_Int32 nPos); + void Insert(const OUString& rStr, sal_Int32 nPos); void Append(std::u16string_view rStr); void Erase(sal_Int32 nPos); void Erase(sal_Int32 nPos, sal_Int32 nCount); diff --git a/editeng/inc/editdoc.hxx b/editeng/inc/editdoc.hxx index ede186b717a5..5a8aa8054b8f 100644 --- a/editeng/inc/editdoc.hxx +++ b/editeng/inc/editdoc.hxx @@ -171,7 +171,7 @@ public: EditPaM Clear(); EditPaM RemoveText(); void RemoveChars( EditPaM aPaM, sal_Int32 nChars ); - EditPaM InsertText( EditPaM aPaM, std::u16string_view rStr ); + EditPaM InsertText( EditPaM aPaM, const OUString& rStr ); EditPaM InsertParaBreak( EditPaM aPaM, bool bKeepEndingAttribs ); EditPaM InsertFeature( EditPaM aPaM, const SfxPoolItem& rItem ); EditPaM ConnectParagraphs( ContentNode* pLeft, ContentNode* pRight ); diff --git a/editeng/source/editeng/ContentNode.cxx b/editeng/source/editeng/ContentNode.cxx index 08bf250b6c86..de5e2150b151 100644 --- a/editeng/source/editeng/ContentNode.cxx +++ b/editeng/source/editeng/ContentNode.cxx @@ -562,9 +562,12 @@ void ContentNode::SetChar(sal_Int32 nPos, sal_Unicode c) maString = maString.replaceAt(nPos, 1, rtl::OUStringChar(c)); } -void ContentNode::Insert(std::u16string_view rStr, sal_Int32 nPos) +void ContentNode::Insert(const OUString& rStr, sal_Int32 nPos) { - maString = maString.replaceAt(nPos, 0, rStr); + if (nPos == 0 && maString.getLength() == 0) + maString = rStr; // avoid allocation + else + maString = maString.replaceAt(nPos, 0, rStr); } void ContentNode::Append(std::u16string_view rStr) diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx index 2a69d5d712b5..12cab1c85230 100644 --- a/editeng/source/editeng/editdoc.cxx +++ b/editeng/source/editeng/editdoc.cxx @@ -1013,16 +1013,17 @@ EditPaM EditDoc::RemoveText() return EditPaM(pNode, 0); } -EditPaM EditDoc::InsertText( EditPaM aPaM, std::u16string_view rStr ) +EditPaM EditDoc::InsertText( EditPaM aPaM, const OUString& rStr ) { - DBG_ASSERT( rStr.find( 0x0A ) == std::u16string_view::npos, "EditDoc::InsertText: Newlines prohibited in paragraph!" ); - DBG_ASSERT( rStr.find( 0x0D ) == std::u16string_view::npos, "EditDoc::InsertText: Newlines prohibited in paragraph!" ); - DBG_ASSERT( rStr.find( ' ' ) == std::u16string_view::npos, "EditDoc::InsertText: Newlines prohibited in paragraph!" ); - assert(aPaM.GetNode()); + DBG_ASSERT( rStr.indexOf( 0x0A ) == -1, "EditDoc::InsertText: Newlines prohibited in paragraph!" ); + DBG_ASSERT( rStr.indexOf( 0x0D ) == -1, "EditDoc::InsertText: Newlines prohibited in paragraph!" ); + DBG_ASSERT( rStr.indexOf( ' ' ) == -1, "EditDoc::InsertText: Newlines prohibited in paragraph!" ); - aPaM.GetNode()->Insert( rStr, aPaM.GetIndex() ); - aPaM.GetNode()->ExpandAttribs( aPaM.GetIndex(), rStr.size() ); - aPaM.SetIndex( aPaM.GetIndex() + rStr.size() ); + ContentNode* pNode = aPaM.GetNode(); + assert(pNode); + pNode->Insert( rStr, aPaM.GetIndex() ); + pNode->ExpandAttribs( aPaM.GetIndex(), rStr.getLength() ); + aPaM.SetIndex( aPaM.GetIndex() + rStr.getLength() ); SetModified( true ); diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index 2123f89ef916..f63a12a5bbc1 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -2867,7 +2867,7 @@ EditPaM ImpEditEngine::ImpInsertText(const EditSelection& aCurSel, const OUStrin nEnd2 = aLine.getLength(); // not dereference! if ( nEnd2 > nStart2 ) - aPaM = maEditDoc.InsertText( aPaM, aLine.subView( nStart2, nEnd2-nStart2 ) ); + aPaM = maEditDoc.InsertText( aPaM, aLine.copy( nStart2, nEnd2-nStart2 ) ); if ( nEnd2 < aLine.getLength() ) { aPaM = maEditDoc.InsertFeature( aPaM, aTabItem );