diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-07-13 17:03:34 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-07-13 20:36:46 +0200 |
commit | 61e8788d1b87fc57a9d015041f4e1ab44a86a1bd (patch) | |
tree | 5bae1af990ea7266140927b2c625b5a0f9265040 | |
parent | 0b6d0ac41afc72a0043e6ccdc6cdfd8648a5efdc (diff) |
convert pXRelTo/pYRelTo to boost::optional
seems wasteful to be allocating a single int for this
Change-Id: I8e1122fec8c8dc90805a38b677a1e08cd89a66ff
Reviewed-on: https://gerrit.libreoffice.org/39917
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | filter/source/msfilter/msdffimp.cxx | 36 | ||||
-rw-r--r-- | include/filter/msfilter/msdffimp.hxx | 8 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8graf.cxx | 28 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par.cxx | 13 |
4 files changed, 29 insertions, 56 deletions
diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx index 6aef843a0c84..e64ec009f1c3 100644 --- a/filter/source/msfilter/msdffimp.cxx +++ b/filter/source/msfilter/msdffimp.cxx @@ -5055,15 +5055,11 @@ SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt, { case 0x038F: pImpRec->nXAlign = nUDData; break; case 0x0390: - delete pImpRec->pXRelTo; - pImpRec->pXRelTo = new sal_uInt32; - *(pImpRec->pXRelTo) = nUDData; + pImpRec->nXRelTo = nUDData; break; case 0x0391: pImpRec->nYAlign = nUDData; break; case 0x0392: - delete pImpRec->pYRelTo; - pImpRec->pYRelTo = new sal_uInt32; - *(pImpRec->pYRelTo) = nUDData; + pImpRec->nYRelTo = nUDData; break; case 0x03BF: pImpRec->nLayoutInTableCell = nUDData; break; case 0x0393: @@ -5424,8 +5420,7 @@ SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt, if (SeekToContent(DFF_Prop_pWrapPolygonVertices, rSt)) { - delete pTextImpRec->pWrapPolygon; - pTextImpRec->pWrapPolygon = nullptr; + pTextImpRec->pWrapPolygon.reset(); sal_uInt16 nNumElemVert(0), nNumElemMemVert(0), nElemSizeVert(0); rSt.ReadUInt16( nNumElemVert ).ReadUInt16( nNumElemMemVert ).ReadUInt16( nElemSizeVert ); bool bOk = false; @@ -5435,7 +5430,7 @@ SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt, } if (bOk) { - pTextImpRec->pWrapPolygon = new tools::Polygon(nNumElemVert); + pTextImpRec->pWrapPolygon.reset(new tools::Polygon(nNumElemVert)); for (sal_uInt16 i = 0; i < nNumElemVert; ++i) { sal_Int32 nX(0), nY(0); @@ -7287,9 +7282,7 @@ SvxMSDffImportRec::SvxMSDffImportRec() pClientDataBuffer( nullptr ), nClientDataLen( 0 ), nXAlign( 0 ), // position n cm from left - pXRelTo( nullptr ), // relative to column nYAlign( 0 ), // position n cm below - pYRelTo( nullptr ), // relative to paragraph nLayoutInTableCell( 0 ), // element is laid out in table cell nFlags( 0 ), nDxTextLeft( 144 ), @@ -7325,9 +7318,9 @@ SvxMSDffImportRec::SvxMSDffImportRec() SvxMSDffImportRec::SvxMSDffImportRec(const SvxMSDffImportRec& rCopy) : pObj( rCopy.pObj ), nXAlign( rCopy.nXAlign ), - pXRelTo( nullptr ), + nXRelTo( rCopy.nXRelTo ), nYAlign( rCopy.nYAlign ), - pYRelTo( nullptr ), + nYRelTo( rCopy.nYRelTo ), nLayoutInTableCell( rCopy.nLayoutInTableCell ), nFlags( rCopy.nFlags ), nDxTextLeft( rCopy.nDxTextLeft ), @@ -7349,16 +7342,6 @@ SvxMSDffImportRec::SvxMSDffImportRec(const SvxMSDffImportRec& rCopy) relativeHorizontalWidth( rCopy.relativeHorizontalWidth ), isHorizontalRule( rCopy.isHorizontalRule ) { - if (rCopy.pXRelTo) - { - pXRelTo = new sal_uInt32; - *pXRelTo = *(rCopy.pXRelTo); - } - if (rCopy.pYRelTo) - { - pYRelTo = new sal_uInt32; - *pYRelTo = *(rCopy.pYRelTo); - } eLineStyle = rCopy.eLineStyle; // GPF-Bug #66227# eLineDashing = rCopy.eLineDashing; bDrawHell = rCopy.bDrawHell; @@ -7390,16 +7373,11 @@ SvxMSDffImportRec::SvxMSDffImportRec(const SvxMSDffImportRec& rCopy) pClientDataBuffer = nullptr; if (rCopy.pWrapPolygon) - pWrapPolygon = new tools::Polygon(*rCopy.pWrapPolygon); - else - pWrapPolygon = nullptr; + pWrapPolygon.reset( new tools::Polygon(*rCopy.pWrapPolygon) ); } SvxMSDffImportRec::~SvxMSDffImportRec() { - delete pWrapPolygon; - delete pXRelTo; - delete pYRelTo; } void SvxMSDffManager::insertShapeId( sal_Int32 nShapeId, SdrObject* pShape ) diff --git a/include/filter/msfilter/msdffimp.hxx b/include/filter/msfilter/msdffimp.hxx index 3dff33e6269c..57530d1da42a 100644 --- a/include/filter/msfilter/msdffimp.hxx +++ b/include/filter/msfilter/msdffimp.hxx @@ -27,6 +27,7 @@ #include <utility> #include <vector> +#include <boost/optional.hpp> #include <com/sun/star/uno/Any.hxx> #include <com/sun/star/uno/Reference.hxx> #include <comphelper/stl_types.hxx> @@ -210,7 +211,8 @@ struct MSFILTER_DLLPUBLIC SvxMSDffImportRec static const int RELTO_DEFAULT = 2; SdrObject* pObj; - tools::Polygon* pWrapPolygon; + std::unique_ptr<tools::Polygon> + pWrapPolygon; std::unique_ptr<char[]> pClientAnchorBuffer; sal_uInt32 nClientAnchorLen; @@ -218,9 +220,9 @@ struct MSFILTER_DLLPUBLIC SvxMSDffImportRec pClientDataBuffer; sal_uInt32 nClientDataLen; sal_uInt32 nXAlign; - sal_uInt32 *pXRelTo; + boost::optional<sal_uInt32> nXRelTo; sal_uInt32 nYAlign; - sal_uInt32 *pYRelTo; + boost::optional<sal_uInt32> nYRelTo; sal_uInt32 nLayoutInTableCell; sal_uInt32 nFlags; sal_Int32 nDxTextLeft; ///< distance of text box from surrounding shape diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx index ed17ef710e36..982696de15ad 100644 --- a/sw/source/filter/ww8/ww8graf.cxx +++ b/sw/source/filter/ww8/ww8graf.cxx @@ -1855,9 +1855,9 @@ void SwWW8ImplReader::AdjustLRWrapForWordMargins( const SvxMSDffImportRec &rRecord, SvxLRSpaceItem &rLR) { sal_uInt32 nXRelTo = SvxMSDffImportRec::RELTO_DEFAULT; - if ( rRecord.pXRelTo ) + if ( rRecord.nXRelTo ) { - nXRelTo = *(rRecord.pXRelTo); + nXRelTo = rRecord.nXRelTo.get(); } // Left adjustments - if horizontally aligned to left of @@ -1893,9 +1893,9 @@ void SwWW8ImplReader::AdjustULWrapForWordMargins( const SvxMSDffImportRec &rRecord, SvxULSpaceItem &rUL) { sal_uInt32 nYRelTo = SvxMSDffImportRec::RELTO_DEFAULT; - if ( rRecord.pYRelTo ) + if ( rRecord.nYRelTo ) { - nYRelTo = *(rRecord.pYRelTo); + nYRelTo = rRecord.nYRelTo.get(); } // Top adjustment - remove upper wrapping if aligned to page @@ -2177,15 +2177,13 @@ RndStdIds SwWW8ImplReader::ProcessEscherAlign(SvxMSDffImportRec* pRecord, SvxMSDffImportRec aRecordFromFSPA; if (!pRecord) pRecord = &aRecordFromFSPA; - if (!(pRecord->pXRelTo) && pFSPA) + if (!(pRecord->nXRelTo) && pFSPA) { - pRecord->pXRelTo = new sal_uInt32; - *(pRecord->pXRelTo) = pFSPA->nbx; + pRecord->nXRelTo = sal_Int32(pFSPA->nbx); } - if (!(pRecord->pYRelTo) && pFSPA) + if (!(pRecord->nYRelTo) && pFSPA) { - pRecord->pYRelTo = new sal_uInt32; - *(pRecord->pYRelTo) = pFSPA->nby; + pRecord->nYRelTo = sal_Int32(pFSPA->nby); } // nXAlign - abs. Position, Left, Centered, Right, Inside, Outside @@ -2208,20 +2206,20 @@ RndStdIds SwWW8ImplReader::ProcessEscherAlign(SvxMSDffImportRec* pRecord, // if X and Y Rel values are on default take it as a hint, that they have not been set // by <SwMSDffManager::ProcessObj(..)> - const bool bXYRelHaveDefaultValues = *(pRecord->pXRelTo) == 2 && *(pRecord->pYRelTo) == 2; + const bool bXYRelHaveDefaultValues = pRecord->nXRelTo.get() == 2 && pRecord->nYRelTo.get() == 2; if ( bXYRelHaveDefaultValues && m_nInTable > 0 && !bCurSectionVertical ) { - if ( pFSPA->nby != *(pRecord->pYRelTo) ) + if ( sal_uInt32(pFSPA->nby) != pRecord->nYRelTo ) { - *(pRecord->pYRelTo) = pFSPA->nby; + pRecord->nYRelTo = sal_uInt32(pFSPA->nby); } } } - sal_uInt32 nXRelTo = (pRecord->pXRelTo && nCntRelTo > *(pRecord->pXRelTo)) ? *(pRecord->pXRelTo) : 1; - sal_uInt32 nYRelTo = (pRecord->pYRelTo && nCntRelTo > *(pRecord->pYRelTo)) ? *(pRecord->pYRelTo) : 1; + sal_uInt32 nXRelTo = (pRecord->nXRelTo && nCntRelTo > pRecord->nXRelTo) ? pRecord->nXRelTo.get() : 1; + sal_uInt32 nYRelTo = (pRecord->nYRelTo && nCntRelTo > pRecord->nYRelTo) ? pRecord->nYRelTo.get() : 1; RndStdIds eAnchor = IsInlineEscherHack() ? RndStdIds::FLY_AS_CHAR : RndStdIds::FLY_AT_CHAR; // #i43718# diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index 05fe2f786455..8ee597c8d921 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -629,15 +629,11 @@ SdrObject* SwMSDffManager::ProcessObj(SvStream& rSt, { case 0x038F: pImpRec->nXAlign = nUDData; break; case 0x0390: - delete pImpRec->pXRelTo; - pImpRec->pXRelTo = new sal_uInt32; - *(pImpRec->pXRelTo) = nUDData; + pImpRec->nXRelTo = nUDData; break; case 0x0391: pImpRec->nYAlign = nUDData; break; case 0x0392: - delete pImpRec->pYRelTo; - pImpRec->pYRelTo = new sal_uInt32; - *(pImpRec->pYRelTo) = nUDData; + pImpRec->nYRelTo = nUDData; break; case 0x03BF: pImpRec->nLayoutInTableCell = nUDData; break; case 0x0393: @@ -993,8 +989,7 @@ SdrObject* SwMSDffManager::ProcessObj(SvStream& rSt, if (SeekToContent(DFF_Prop_pWrapPolygonVertices, rSt)) { - delete pImpRec->pWrapPolygon; - pImpRec->pWrapPolygon = nullptr; + pImpRec->pWrapPolygon.reset(); sal_uInt16 nNumElemVert(0), nNumElemMemVert(0), nElemSizeVert(0); rSt.ReadUInt16( nNumElemVert ).ReadUInt16( nNumElemMemVert ).ReadUInt16( nElemSizeVert ); @@ -1007,7 +1002,7 @@ SdrObject* SwMSDffManager::ProcessObj(SvStream& rSt, } if (bOk) { - pImpRec->pWrapPolygon = new tools::Polygon(nNumElemVert); + pImpRec->pWrapPolygon.reset( new tools::Polygon(nNumElemVert) ); for (sal_uInt16 i = 0; i < nNumElemVert; ++i) { sal_Int32 nX(0), nY(0); |