summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2024-05-29 18:46:00 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-05-30 09:17:27 +0200
commitee4d61b08dabe1c184a49c7301a301ed0dcfc710 (patch)
tree2b3666b68badf8694846171629ad658124bf4a59 /sw
parent322a6ca8f912513f69747a68fe5497ee6b643293 (diff)
reduce heap allocation
Change-Id: I9e99244cb6a5e79e8856eefceac16cacbca49a96 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168230 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/unocrsrhelper.hxx3
-rw-r--r--sw/source/core/unocore/unocrsrhelper.cxx17
-rw-r--r--sw/source/uibase/uno/unotxvw.cxx6
3 files changed, 13 insertions, 13 deletions
diff --git a/sw/inc/unocrsrhelper.hxx b/sw/inc/unocrsrhelper.hxx
index 17a86716c318..d7f8dc3f22ef 100644
--- a/sw/inc/unocrsrhelper.hxx
+++ b/sw/inc/unocrsrhelper.hxx
@@ -23,6 +23,7 @@
#include "flyenum.hxx"
#include "pam.hxx"
+#include <optional>
#include <map>
#include <string_view>
@@ -232,7 +233,7 @@ namespace SwUnoCursorHelper
SW_DLLPUBLIC void GetSelectableFromAny(
css::uno::Reference<css::uno::XInterface> const& xIfc,
SwDoc & rTargetDoc,
- SwPaM *& o_rpPaM, std::pair<OUString, FlyCntType> & o_rFrame,
+ std::optional<SwPaM>& o_rpPaM, std::pair<OUString, FlyCntType> & o_rFrame,
OUString & o_rTableName, SwUnoTableCursor const*& o_rpTableCursor,
::sw::mark::IMark const*& o_rpMark,
std::vector<SdrObject *> & o_rSdrObjects);
diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx
index d8868d4f1b02..88c2baafd61d 100644
--- a/sw/source/core/unocore/unocrsrhelper.cxx
+++ b/sw/source/core/unocore/unocrsrhelper.cxx
@@ -105,16 +105,15 @@ using namespace ::com::sun::star::lang;
namespace SwUnoCursorHelper
{
-static SwPaM* lcl_createPamCopy(const SwPaM& rPam)
+static void lcl_createPamCopy(std::optional<SwPaM>& o_rpPam, const SwPaM& rPam)
{
- SwPaM *const pRet = new SwPaM(*rPam.GetPoint());
- ::sw::DeepCopyPaM(rPam, *pRet);
- return pRet;
+ o_rpPam.emplace(*rPam.GetPoint());
+ ::sw::DeepCopyPaM(rPam, *o_rpPam);
}
void GetSelectableFromAny(uno::Reference<uno::XInterface> const& xIfc,
SwDoc & rTargetDoc,
- SwPaM *& o_rpPaM, std::pair<OUString, FlyCntType> & o_rFrame,
+ std::optional<SwPaM>& o_rpPaM, std::pair<OUString, FlyCntType> & o_rFrame,
OUString & o_rTableName, SwUnoTableCursor const*& o_rpTableCursor,
::sw::mark::IMark const*& o_rpMark,
std::vector<SdrObject *> & o_rSdrObjects)
@@ -166,7 +165,7 @@ void GetSelectableFromAny(uno::Reference<uno::XInterface> const& xIfc,
{
if (pCursor->GetDoc() == &rTargetDoc)
{
- o_rpPaM = lcl_createPamCopy(*pCursor->GetPaM());
+ lcl_createPamCopy(o_rpPaM, *pCursor->GetPaM());
}
return;
}
@@ -177,7 +176,7 @@ void GetSelectableFromAny(uno::Reference<uno::XInterface> const& xIfc,
SwUnoCursor const* pUnoCursor = pRanges->GetCursor();
if (pUnoCursor && &pUnoCursor->GetDoc() == &rTargetDoc)
{
- o_rpPaM = lcl_createPamCopy(*pUnoCursor);
+ lcl_createPamCopy(o_rpPaM, *pUnoCursor);
}
return;
}
@@ -220,7 +219,7 @@ void GetSelectableFromAny(uno::Reference<uno::XInterface> const& xIfc,
{
SwPaM aPam(*pBox->GetSttNd());
aPam.Move(fnMoveForward, GoInNode);
- o_rpPaM = lcl_createPamCopy(aPam);
+ lcl_createPamCopy(o_rpPaM, aPam);
}
}
return;
@@ -232,7 +231,7 @@ void GetSelectableFromAny(uno::Reference<uno::XInterface> const& xIfc,
SwUnoInternalPaM aPam(rTargetDoc);
if (::sw::XTextRangeToSwPaM(aPam, xTextRange))
{
- o_rpPaM = lcl_createPamCopy(aPam);
+ lcl_createPamCopy(o_rpPaM, aPam);
}
return;
}
diff --git a/sw/source/uibase/uno/unotxvw.cxx b/sw/source/uibase/uno/unotxvw.cxx
index fd6e6fdf8bb6..b0ea0d2318ac 100644
--- a/sw/source/uibase/uno/unotxvw.cxx
+++ b/sw/source/uibase/uno/unotxvw.cxx
@@ -151,7 +151,7 @@ sal_Bool SwXTextView::select(const uno::Any& aInterface)
}
else
{
- SwPaM * pPaM(nullptr);
+ std::optional<SwPaM> pPaM;
std::pair<OUString, FlyCntType> frame;
OUString tableName;
SwUnoTableCursor const* pTableCursor(nullptr);
@@ -163,12 +163,12 @@ sal_Bool SwXTextView::select(const uno::Any& aInterface)
rSh.EnterStdMode();
rSh.SetSelection(*pPaM);
// the pPaM has been copied - delete it
- while (pPaM->GetNext() != pPaM)
+ while (pPaM->GetNext() != &*pPaM)
{
// coverity[deref_arg] - the SwPaM delete moves a new entry into GetNext()
delete pPaM->GetNext();
}
- delete pPaM;
+ pPaM.reset();
return true;
}
else if (!frame.first.isEmpty())