summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2021-08-15 17:35:58 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-08-16 12:07:15 +0200
commiteec42f0dbcc79a4c9f456ce97fa1066b8031ea28 (patch)
treef089f757270293bd94dfac881c62520af76975e0 /editeng
parenta6ca6215a5ec82e833ebfcd2ebd4455cb504fd8e (diff)
pass OutlinerParaObject around by value
since it uses o3tl::cow_wrapper, so it is really just a wrapper around a pointer, no point in allocating it on the heap Remove assert in SdrText::SetOutlinerParaObject, which was bogus anyhow, because it was comparing pointers, not deep equality. And since we are now being more efficient and avoiding copying of the internal data in OutlinerParaObject, we hit this assert. Change-Id: I6dbfaab5ee2ca05b2001baf63110041e469df9c5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120510 Tested-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'editeng')
-rw-r--r--editeng/source/outliner/outliner.cxx21
-rw-r--r--editeng/source/outliner/outlobj.cxx11
-rw-r--r--editeng/source/outliner/overflowingtxt.cxx22
-rw-r--r--editeng/source/uno/unoforou.cxx2
4 files changed, 33 insertions, 23 deletions
diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx
index b30de5d206a0..7370c5666313 100644
--- a/editeng/source/outliner/outliner.cxx
+++ b/editeng/source/outliner/outliner.cxx
@@ -358,7 +358,7 @@ sal_Int32 Outliner::GetBulletsNumberingStatus() const
: 2;
}
-std::unique_ptr<OutlinerParaObject> Outliner::CreateParaObject( sal_Int32 nStartPara, sal_Int32 nCount ) const
+std::optional<OutlinerParaObject> Outliner::CreateParaObject( sal_Int32 nStartPara, sal_Int32 nCount ) const
{
if ( static_cast<sal_uLong>(nStartPara) + nCount >
o3tl::make_unsigned(pParaList->GetParagraphCount()) )
@@ -370,7 +370,7 @@ std::unique_ptr<OutlinerParaObject> Outliner::CreateParaObject( sal_Int32 nStart
nCount = pEditEngine->GetParagraphCount() - nStartPara;
if (nCount <= 0)
- return nullptr;
+ return std::nullopt;
std::unique_ptr<EditTextObject> xText = pEditEngine->CreateTextObject( nStartPara, nCount );
const bool bIsEditDoc(OutlinerMode::TextObject == GetOutlinerMode());
@@ -382,16 +382,15 @@ std::unique_ptr<OutlinerParaObject> Outliner::CreateParaObject( sal_Int32 nStart
aParagraphDataVector[nPara-nStartPara] = *GetParagraph(nPara);
}
- std::unique_ptr<OutlinerParaObject> pPObj(new OutlinerParaObject(std::move(xText), aParagraphDataVector, bIsEditDoc));
- pPObj->SetOutlinerMode(GetOutlinerMode());
+ OutlinerParaObject aPObj(std::move(xText), aParagraphDataVector, bIsEditDoc);
+ aPObj.SetOutlinerMode(GetOutlinerMode());
- return pPObj;
+ return aPObj;
}
void Outliner::SetToEmptyText()
{
- std::unique_ptr<OutlinerParaObject> pEmptyTxt = GetEmptyParaObject();
- SetText(*pEmptyTxt);
+ SetText(GetEmptyParaObject());
}
void Outliner::SetText( const OUString& rText, Paragraph* pPara )
@@ -2118,12 +2117,12 @@ std::optional<NonOverflowingText> Outliner::GetNonOverflowingText() const
}
}
-std::unique_ptr<OutlinerParaObject> Outliner::GetEmptyParaObject() const
+OutlinerParaObject Outliner::GetEmptyParaObject() const
{
std::unique_ptr<EditTextObject> pEmptyText = pEditEngine->GetEmptyTextObject();
- std::unique_ptr<OutlinerParaObject> pPObj( new OutlinerParaObject( std::move(pEmptyText) ));
- pPObj->SetOutlinerMode(GetOutlinerMode());
- return pPObj;
+ OutlinerParaObject aPObj( std::move(pEmptyText) );
+ aPObj.SetOutlinerMode(GetOutlinerMode());
+ return aPObj;
}
std::optional<OverflowingText> Outliner::GetOverflowingText() const
diff --git a/editeng/source/outliner/outlobj.cxx b/editeng/source/outliner/outlobj.cxx
index e8cbd6dbd565..0c0050ebaded 100644
--- a/editeng/source/outliner/outlobj.cxx
+++ b/editeng/source/outliner/outlobj.cxx
@@ -77,6 +77,11 @@ OutlinerParaObject::OutlinerParaObject( const OutlinerParaObject& r ) :
{
}
+OutlinerParaObject::OutlinerParaObject( OutlinerParaObject&& r ) noexcept :
+ mpImpl(std::move(r.mpImpl))
+{
+}
+
OutlinerParaObject::~OutlinerParaObject()
{
}
@@ -87,6 +92,12 @@ OutlinerParaObject& OutlinerParaObject::operator=( const OutlinerParaObject& r )
return *this;
}
+OutlinerParaObject& OutlinerParaObject::operator=( OutlinerParaObject&& r ) noexcept
+{
+ mpImpl = std::move(r.mpImpl);
+ return *this;
+}
+
bool OutlinerParaObject::operator==( const OutlinerParaObject& r ) const
{
return r.mpImpl == mpImpl;
diff --git a/editeng/source/outliner/overflowingtxt.cxx b/editeng/source/outliner/overflowingtxt.cxx
index 0c038dbfb311..ca7f363010d1 100644
--- a/editeng/source/outliner/overflowingtxt.cxx
+++ b/editeng/source/outliner/overflowingtxt.cxx
@@ -30,7 +30,7 @@
#include <editdoc.hxx>
-std::unique_ptr<OutlinerParaObject> TextChainingUtils::JuxtaposeParaObject(
+std::optional<OutlinerParaObject> TextChainingUtils::JuxtaposeParaObject(
css::uno::Reference< css::datatransfer::XTransferable > const & xOverflowingContent,
Outliner *pOutl,
OutlinerParaObject const *pNextPObj)
@@ -65,7 +65,7 @@ std::unique_ptr<OutlinerParaObject> TextChainingUtils::JuxtaposeParaObject(
return pOutl->CreateParaObject();
}
-std::unique_ptr<OutlinerParaObject> TextChainingUtils::DeeplyMergeParaObject(
+std::optional<OutlinerParaObject> TextChainingUtils::DeeplyMergeParaObject(
css::uno::Reference< css::datatransfer::XTransferable > const & xOverflowingContent,
Outliner *pOutl,
OutlinerParaObject const *pNextPObj)
@@ -122,7 +122,7 @@ bool NonOverflowingText::IsLastParaInterrupted() const
}
-std::unique_ptr<OutlinerParaObject> NonOverflowingText::RemoveOverflowingText(Outliner *pOutliner) const
+std::optional<OutlinerParaObject> NonOverflowingText::RemoveOverflowingText(Outliner *pOutliner) const
{
pOutliner->QuickDelete(maContentSel);
SAL_INFO("editeng.chaining", "Deleting selection from (Para: " << maContentSel.nStartPara
@@ -141,12 +141,12 @@ ESelection NonOverflowingText::GetOverflowPointSel() const
// The equivalent of ToParaObject for OverflowingText. Here we are prepending the overflowing text to the old dest box's text
// XXX: In a sense a better name for OverflowingText and NonOverflowingText are respectively DestLinkText and SourceLinkText
-std::unique_ptr<OutlinerParaObject> OverflowingText::JuxtaposeParaObject(Outliner *pOutl, OutlinerParaObject const *pNextPObj)
+std::optional<OutlinerParaObject> OverflowingText::JuxtaposeParaObject(Outliner *pOutl, OutlinerParaObject const *pNextPObj)
{
return TextChainingUtils::JuxtaposeParaObject(mxOverflowingContent, pOutl, pNextPObj);
}
-std::unique_ptr<OutlinerParaObject> OverflowingText::DeeplyMergeParaObject(Outliner *pOutl, OutlinerParaObject const *pNextPObj)
+std::optional<OutlinerParaObject> OverflowingText::DeeplyMergeParaObject(Outliner *pOutl, OutlinerParaObject const *pNextPObj)
{
return TextChainingUtils::DeeplyMergeParaObject(mxOverflowingContent, pOutl, pNextPObj);
}
@@ -170,11 +170,11 @@ ESelection OFlowChainedText::GetOverflowPointSel() const
return mpNonOverflowingTxt->GetOverflowPointSel();
}
-std::unique_ptr<OutlinerParaObject> OFlowChainedText::InsertOverflowingText(Outliner *pOutliner, OutlinerParaObject const *pTextToBeMerged)
+std::optional<OutlinerParaObject> OFlowChainedText::InsertOverflowingText(Outliner *pOutliner, OutlinerParaObject const *pTextToBeMerged)
{
// Just return the roughly merged paras for now
if (!mpOverflowingTxt)
- return nullptr;
+ return std::nullopt;
if (mbIsDeepMerge) {
SAL_INFO("editeng.chaining", "[TEXTCHAINFLOW - OF] Deep merging paras" );
@@ -186,10 +186,10 @@ std::unique_ptr<OutlinerParaObject> OFlowChainedText::InsertOverflowingText(Outl
}
-std::unique_ptr<OutlinerParaObject> OFlowChainedText::RemoveOverflowingText(Outliner *pOutliner)
+std::optional<OutlinerParaObject> OFlowChainedText::RemoveOverflowingText(Outliner *pOutliner)
{
if (!mpNonOverflowingTxt)
- return nullptr;
+ return std::nullopt;
return mpNonOverflowingTxt->RemoveOverflowingText(pOutliner);
}
@@ -207,9 +207,9 @@ UFlowChainedText::UFlowChainedText(Outliner const *pOutl, bool bIsDeepMerge)
mbIsDeepMerge = bIsDeepMerge;
}
-std::unique_ptr<OutlinerParaObject> UFlowChainedText::CreateMergedUnderflowParaObject(Outliner *pOutl, OutlinerParaObject const *pNextLinkWholeText)
+std::optional<OutlinerParaObject> UFlowChainedText::CreateMergedUnderflowParaObject(Outliner *pOutl, OutlinerParaObject const *pNextLinkWholeText)
{
- std::unique_ptr<OutlinerParaObject> pNewText;
+ std::optional<OutlinerParaObject> pNewText;
if (mbIsDeepMerge) {
SAL_INFO("editeng.chaining", "[TEXTCHAINFLOW - UF] Deep merging paras" );
diff --git a/editeng/source/uno/unoforou.cxx b/editeng/source/uno/unoforou.cxx
index 144126d25e08..e348e254ea28 100644
--- a/editeng/source/uno/unoforou.cxx
+++ b/editeng/source/uno/unoforou.cxx
@@ -541,7 +541,7 @@ void SvxOutlinerForwarder::CopyText(const SvxTextForwarder& rSource)
const SvxOutlinerForwarder* pSourceForwarder = dynamic_cast< const SvxOutlinerForwarder* >( &rSource );
if( !pSourceForwarder )
return;
- std::unique_ptr<OutlinerParaObject> pNewOutlinerParaObject = pSourceForwarder->rOutliner.CreateParaObject();
+ std::optional<OutlinerParaObject> pNewOutlinerParaObject = pSourceForwarder->rOutliner.CreateParaObject();
rOutliner.SetText( *pNewOutlinerParaObject );
}