summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2023-05-02 19:38:54 +0900
committerTomaž Vajngerl <quikee@gmail.com>2023-05-03 02:31:31 +0200
commit98726695af0e3a673618d16b981818155d43bc0c (patch)
treed1ac252e2f50ee29b744e2304534aee49eb5b59b /sw
parent2d0a87f97e2c9ac50cd6ce329ca8256daf94ead4 (diff)
simplify SwSortUndoElement
No need for a union to save the minimal amount of memory. The code is much harder to read an more error prone. Just duplicate source and target - in one kace to be SwNodeOffset and other as OUString. The assumption that SwNodeOffset doesn't have a default constr. is also not true anymore, so we can just freely use that. Change-Id: Ia96182eb2f872d0ca8f2e71ef2258d4b929c2d20 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151263 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/core/inc/UndoSort.hxx39
-rw-r--r--sw/source/core/undo/unsort.cxx39
2 files changed, 25 insertions, 53 deletions
diff --git a/sw/source/core/inc/UndoSort.hxx b/sw/source/core/inc/UndoSort.hxx
index 81cb33c60787..432dd41133d9 100644
--- a/sw/source/core/inc/UndoSort.hxx
+++ b/sw/source/core/inc/UndoSort.hxx
@@ -34,30 +34,20 @@ class SwUndoAttrTable;
struct SwSortUndoElement
{
- union {
- struct {
- sal_uLong nID;
- // we cannot store these as SwNodeOffset (even though they are)
- // because SwNodeOffset has no default constructor
- sal_Int32 nSource, nTarget;
- } TXT;
- struct {
- OUString *pSource, *pTarget;
- } TBL;
- } SORT_TXT_TBL;
+ OUString maSourceString;
+ OUString maTargetString;
+ SwNodeOffset mnSourceNodeOffset;
+ SwNodeOffset mnTargetNodeOffset;
- SwSortUndoElement( const OUString& aS, const OUString& aT )
- {
- SORT_TXT_TBL.TBL.pSource = new OUString( aS );
- SORT_TXT_TBL.TBL.pTarget = new OUString( aT );
- }
- SwSortUndoElement( SwNodeOffset nS, SwNodeOffset nT )
- {
- SORT_TXT_TBL.TXT.nSource = sal_Int32(nS);
- SORT_TXT_TBL.TXT.nTarget = sal_Int32(nT);
- SORT_TXT_TBL.TXT.nID = 0xffffffff;
- }
- ~SwSortUndoElement();
+ SwSortUndoElement(const OUString& aSource, const OUString& aTarget)
+ : maSourceString(aSource)
+ , maTargetString(aTarget)
+ {}
+
+ SwSortUndoElement(SwNodeOffset nSource, SwNodeOffset nTarget)
+ : mnSourceNodeOffset(nSource)
+ , mnTargetNodeOffset(nTarget)
+ {}
};
class SwUndoSort final : public SwUndo, private SwUndRng
@@ -67,8 +57,7 @@ class SwUndoSort final : public SwUndo, private SwUndRng
std::unique_ptr<SwUndoAttrTable> m_pUndoAttrTable;
SwNodeOffset m_nTableNode;
-public:
- SwUndoSort( const SwPaM&, const SwSortOptions& );
+public: SwUndoSort( const SwPaM&, const SwSortOptions& );
SwUndoSort( SwNodeOffset nStt, SwNodeOffset nEnd, const SwTableNode&,
const SwSortOptions&, bool bSaveTable );
diff --git a/sw/source/core/undo/unsort.cxx b/sw/source/core/undo/unsort.cxx
index 26d151b8c517..bf188918a435 100644
--- a/sw/source/core/undo/unsort.cxx
+++ b/sw/source/core/undo/unsort.cxx
@@ -30,17 +30,6 @@
#include <docsort.hxx>
#include <node2lay.hxx>
-// Undo for Sorting
-SwSortUndoElement::~SwSortUndoElement()
-{
- // are there string pointers saved?
- if( 0xffffffff != SORT_TXT_TBL.TXT.nID )
- {
- delete SORT_TXT_TBL.TBL.pSource;
- delete SORT_TXT_TBL.TBL.pTarget;
- }
-}
-
SwUndoSort::SwUndoSort(const SwPaM& rRg, const SwSortOptions& rOpt)
: SwUndo(SwUndoId::SORT_TXT, &rRg.GetDoc())
, SwUndRng(rRg)
@@ -91,12 +80,10 @@ void SwUndoSort::UndoImpl(::sw::UndoRedoContext & rContext)
const SwTable& rTable = pTableNd->GetTable();
SwMovedBoxes aMovedList;
- for (const std::unique_ptr<SwSortUndoElement> & i : m_SortList)
+ for (std::unique_ptr<SwSortUndoElement> const& pElement : m_SortList)
{
- const SwTableBox* pSource = rTable.GetTableBox(
- *i->SORT_TXT_TBL.TBL.pSource );
- const SwTableBox* pTarget = rTable.GetTableBox(
- *i->SORT_TXT_TBL.TBL.pTarget );
+ const SwTableBox* pSource = rTable.GetTableBox(pElement->maSourceString);
+ const SwTableBox* pTarget = rTable.GetTableBox(pElement->maTargetString);
// move back
MoveCell(&rDoc, pTarget, pSource,
@@ -125,12 +112,11 @@ void SwUndoSort::UndoImpl(::sw::UndoRedoContext & rContext)
for (size_t i = 0; i < m_SortList.size(); ++i)
{
- for (const std::unique_ptr<SwSortUndoElement> & j : m_SortList)
+ for (std::unique_ptr<SwSortUndoElement> const& pElement : m_SortList)
{
- if (j->SORT_TXT_TBL.TXT.nSource == sal_Int32(m_nSttNode + SwNodeOffset(i)))
+ if (pElement->mnSourceNodeOffset == (m_nSttNode + SwNodeOffset(i)))
{
- aIdxList.push_back( SwNodeIndex( rDoc.GetNodes(),
- j->SORT_TXT_TBL.TXT.nTarget ) );
+ aIdxList.push_back( SwNodeIndex(rDoc.GetNodes(), pElement->mnTargetNodeOffset));
break;
}
}
@@ -168,12 +154,10 @@ void SwUndoSort::RedoImpl(::sw::UndoRedoContext & rContext)
const SwTable& rTable = pTableNd->GetTable();
SwMovedBoxes aMovedList;
- for (const std::unique_ptr<SwSortUndoElement> & i : m_SortList)
+ for (std::unique_ptr<SwSortUndoElement> const& pElement: m_SortList)
{
- const SwTableBox* pSource = rTable.GetTableBox(
- *i->SORT_TXT_TBL.TBL.pSource );
- const SwTableBox* pTarget = rTable.GetTableBox(
- *i->SORT_TXT_TBL.TBL.pTarget );
+ const SwTableBox* pSource = rTable.GetTableBox(pElement->maSourceString);
+ const SwTableBox* pTarget = rTable.GetTableBox(pElement->maTargetString);
// move back
MoveCell(&rDoc, pSource, pTarget,
@@ -205,8 +189,7 @@ void SwUndoSort::RedoImpl(::sw::UndoRedoContext & rContext)
for (size_t i = 0; i < m_SortList.size(); ++i)
{ // current position is starting point
- aIdxList.push_back( SwNodeIndex( rDoc.GetNodes(),
- m_SortList[i]->SORT_TXT_TBL.TXT.nSource) );
+ aIdxList.push_back( SwNodeIndex(rDoc.GetNodes(), m_SortList[i]->mnSourceNodeOffset) );
}
for (size_t i = 0; i < m_SortList.size(); ++i)
@@ -242,7 +225,7 @@ void SwUndoSort::RepeatImpl(::sw::RepeatContext & rContext)
void SwUndoSort::Insert( const OUString& rOrgPos, const OUString& rNewPos)
{
- m_SortList.push_back(std::make_unique< SwSortUndoElement>(rOrgPos, rNewPos));
+ m_SortList.push_back(std::make_unique<SwSortUndoElement>(rOrgPos, rNewPos));
}
void SwUndoSort::Insert( SwNodeOffset nOrgPos, SwNodeOffset nNewPos)