[Libreoffice-commits] core.git: 2 commits - framework/source include/o3tl sw/source
Noel Grandin
noel.grandin at collabora.co.uk
Thu Jun 15 06:25:18 UTC 2017
framework/source/uielement/menubarmanager.cxx | 3 +--
include/o3tl/make_unique.hxx | 16 ++++++++++++++++
sw/source/core/doc/docsort.cxx | 12 ++++--------
sw/source/core/inc/docsort.hxx | 2 +-
4 files changed, 22 insertions(+), 11 deletions(-)
New commits:
commit 3f20471490c61b19fe4222f8c40df255051f6e3d
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Wed Jun 14 15:58:42 2017 +0200
use std::unique_ptr in FlatFndBox
and extend o3tl::make_unique to cope with arrays
Change-Id: I84caa46ab5060f9777bfe275f229499cb0b407be
Reviewed-on: https://gerrit.libreoffice.org/38794
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/include/o3tl/make_unique.hxx b/include/o3tl/make_unique.hxx
index 2be03e9dc9cf..40658f5734d4 100644
--- a/include/o3tl/make_unique.hxx
+++ b/include/o3tl/make_unique.hxx
@@ -12,6 +12,7 @@
#include <memory>
#include <utility>
+#include <type_traits>
namespace o3tl
{
@@ -27,6 +28,21 @@ typename std::unique_ptr<T> make_unique(Args&& ... args)
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
+/**
+ * for arrays
+ */
+template <class T>
+typename std::enable_if
+<
+ std::is_array<T>::value,
+ std::unique_ptr<T>
+>::type
+make_unique(std::size_t n)
+{
+ typedef typename std::remove_extent<T>::type RT;
+ return std::unique_ptr<T>(new RT[n]);
+}
+
}
#endif
diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx
index d71f9a079426..f2c02f409342 100644
--- a/sw/source/core/doc/docsort.cxx
+++ b/sw/source/core/doc/docsort.cxx
@@ -747,7 +747,6 @@ void MoveCell(SwDoc* pDoc, const SwTableBox* pSource, const SwTableBox* pTar,
FlatFndBox::FlatFndBox(SwDoc* pDocPtr, const FndBox_& rBox) :
pDoc(pDocPtr),
rBoxRef(rBox),
- pArr(nullptr),
nRow(0),
nCol(0)
{ // If the array is symmetric
@@ -760,9 +759,8 @@ FlatFndBox::FlatFndBox(SwDoc* pDocPtr, const FndBox_& rBox) :
// Create linear array
size_t nCount = static_cast<size_t>(nRows) * nCols;
- pArr = new const FndBox_*[nCount];
- FndBox_** ppTmp = const_cast<FndBox_**>(pArr);
- memset(ppTmp, 0, sizeof(const FndBox_*) * nCount);
+ pArr = o3tl::make_unique<FndBox_ const *[]>(nCount);
+ memset(pArr.get(), 0, sizeof(const FndBox_*) * nCount);
FillFlat( rBoxRef );
}
@@ -770,8 +768,6 @@ FlatFndBox::FlatFndBox(SwDoc* pDocPtr, const FndBox_& rBox) :
FlatFndBox::~FlatFndBox()
{
- FndBox_** ppTmp = const_cast<FndBox_**>(pArr);
- delete [] ppTmp;
}
/// All Lines of a Box need to have same number of Boxes
@@ -890,7 +886,7 @@ void FlatFndBox::FillFlat(const FndBox_& rBox, bool bLastBox)
{
// save it
sal_uInt16 nOff = nRow * nCols + nCol;
- *(pArr + nOff) = pBox;
+ pArr[nOff] = pBox;
// Save the Formula/Format/Value values
const SwFrameFormat* pFormat = pBox->GetBox()->GetFrameFormat();
@@ -931,7 +927,7 @@ void FlatFndBox::FillFlat(const FndBox_& rBox, bool bLastBox)
const FndBox_* FlatFndBox::GetBox(sal_uInt16 n_Col, sal_uInt16 n_Row) const
{
sal_uInt16 nOff = n_Row * nCols + n_Col;
- const FndBox_* pTmp = *(pArr + nOff);
+ const FndBox_* pTmp = pArr[nOff];
OSL_ENSURE(n_Col < nCols && n_Row < nRows && pTmp, "invalid array access");
return pTmp;
diff --git a/sw/source/core/inc/docsort.hxx b/sw/source/core/inc/docsort.hxx
index f8c1990ef9a3..b66ecd3f5159 100644
--- a/sw/source/core/inc/docsort.hxx
+++ b/sw/source/core/inc/docsort.hxx
@@ -140,7 +140,7 @@ private:
SwDoc* pDoc;
const FndBox_& rBoxRef;
- const FndBox_** pArr;
+ std::unique_ptr<FndBox_ const *[]> pArr;
std::vector<std::unique_ptr<SfxItemSet>> ppItemSets;
sal_uInt16 nRows;
commit 8ae592a7360d5f6a44d5ad2c34d818f638ff94b2
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Wed Jun 14 15:26:23 2017 +0200
fix bug in MenuBarManager::FillMenuManager
which appears to have been there since this function was created in
commit 635d8b5b0c2152efb80694bb27fa8df9487b108d
Author: Kurt Zenker <kz at openoffice.org>
Date: Wed Feb 25 16:51:59 2004 +0000
INTEGRATION: CWS layoutmanager (1.1.2); FILE ADDED
Change-Id: I117241152e99f1ee6ec33e32f8fdc63ae7c87043
Reviewed-on: https://gerrit.libreoffice.org/38791
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/framework/source/uielement/menubarmanager.cxx b/framework/source/uielement/menubarmanager.cxx
index 023dc79f1332..2dcfd3a94920 100644
--- a/framework/source/uielement/menubarmanager.cxx
+++ b/framework/source/uielement/menubarmanager.cxx
@@ -1180,8 +1180,7 @@ void MenuBarManager::FillMenuManager( Menu* pMenu, const Reference< XFrame >& rF
VclPtr<PopupMenu> pSubMenu = AddonMenuManager::CreateAddonMenu(rFrame);
if ( pSubMenu && ( pSubMenu->GetItemCount() > 0 ))
{
- sal_uInt16 nCount = 0;
- if ( pPopup->GetItemType( nCount-1 ) != MenuItemType::SEPARATOR )
+ if ( pPopup->GetItemType( pPopup->GetItemCount() - 1 ) != MenuItemType::SEPARATOR )
pPopup->InsertSeparator();
pPopup->InsertItem( ITEMID_ADDONLIST, OUString() );
More information about the Libreoffice-commits
mailing list