Kaydet (Commit) d5af010a authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Allocate ImpXPolygon::pPointAry as a true Point[]

...as the default Point ctor already zero-initializes its members, remvoing the
need for some memset calls (that cause -Werror=class-memaccess, "clearing an
object of non-trivial type ‘class Point’" with upcoming GCC 8).  Other such
problematic memset calls are replaced with std::fill, which appears to produce
adequate code with recent compilers (looked at GCC 7.2 and 8, Clang 7, at -O2),
a tight loop of filling the memory with zeroes.

A follow-up commit might want to use unique_ptr or vector for pPointAry.

Change-Id: I566422b2213643ab762f0d87a25e745ec2f35ee4
Reviewed-on: https://gerrit.libreoffice.org/48488Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 90269841
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <sal/config.h>
#include <algorithm>
#include <osl/endian.h> #include <osl/endian.h>
#include <tools/stream.hxx> #include <tools/stream.hxx>
#include <tools/debug.hxx> #include <tools/debug.hxx>
...@@ -67,10 +71,10 @@ ImpXPolygon::ImpXPolygon( const ImpXPolygon& rImpXPoly ) ...@@ -67,10 +71,10 @@ ImpXPolygon::ImpXPolygon( const ImpXPolygon& rImpXPoly )
ImpXPolygon::~ImpXPolygon() ImpXPolygon::~ImpXPolygon()
{ {
delete[] reinterpret_cast<char*>(pPointAry); delete[] pPointAry;
if ( bDeleteOldPoints ) if ( bDeleteOldPoints )
{ {
delete[] reinterpret_cast<char*>(pOldPointAry); delete[] pOldPointAry;
pOldPointAry = nullptr; pOldPointAry = nullptr;
} }
} }
...@@ -111,8 +115,7 @@ void ImpXPolygon::Resize( sal_uInt16 nNewSize, bool bDeletePoints ) ...@@ -111,8 +115,7 @@ void ImpXPolygon::Resize( sal_uInt16 nNewSize, bool bDeletePoints )
} }
// create point array // create point array
nSize = nNewSize; nSize = nNewSize;
pPointAry = reinterpret_cast<Point*>(new char[ nSize*sizeof( Point ) ]); pPointAry = new Point[ nSize ];
memset( pPointAry, 0, nSize*sizeof( Point ) );
// create flag array // create flag array
pFlagAry.reset( new PolyFlags[ nSize ] ); pFlagAry.reset( new PolyFlags[ nSize ] );
...@@ -137,7 +140,7 @@ void ImpXPolygon::Resize( sal_uInt16 nNewSize, bool bDeletePoints ) ...@@ -137,7 +140,7 @@ void ImpXPolygon::Resize( sal_uInt16 nNewSize, bool bDeletePoints )
} }
if ( bDeletePoints ) if ( bDeletePoints )
{ {
delete[] reinterpret_cast<char*>(pOldPointAry); delete[] pOldPointAry;
pOldPointAry = nullptr; pOldPointAry = nullptr;
} }
else else
...@@ -165,7 +168,7 @@ void ImpXPolygon::InsertSpace( sal_uInt16 nPos, sal_uInt16 nCount ) ...@@ -165,7 +168,7 @@ void ImpXPolygon::InsertSpace( sal_uInt16 nPos, sal_uInt16 nCount )
nMove * sizeof(Point) ); nMove * sizeof(Point) );
memmove( &pFlagAry[nPos+nCount], &pFlagAry[nPos], nMove ); memmove( &pFlagAry[nPos+nCount], &pFlagAry[nPos], nMove );
} }
memset( &pPointAry[nPos], 0, nCount * sizeof( Point ) ); std::fill(pPointAry + nPos, pPointAry + nPos + nCount, Point());
memset( &pFlagAry [nPos], 0, nCount ); memset( &pFlagAry [nPos], 0, nCount );
nPoints = nPoints + nCount; nPoints = nPoints + nCount;
...@@ -185,7 +188,7 @@ void ImpXPolygon::Remove( sal_uInt16 nPos, sal_uInt16 nCount ) ...@@ -185,7 +188,7 @@ void ImpXPolygon::Remove( sal_uInt16 nPos, sal_uInt16 nCount )
nMove * sizeof(Point) ); nMove * sizeof(Point) );
memmove( &pFlagAry[nPos], &pFlagAry[nPos+nCount], nMove ); memmove( &pFlagAry[nPos], &pFlagAry[nPos+nCount], nMove );
} }
memset( &pPointAry[nPoints - nCount], 0, nCount * sizeof( Point ) ); std::fill(pPointAry + (nPoints - nCount), pPointAry + nPoints, Point());
memset( &pFlagAry [nPoints - nCount], 0, nCount ); memset( &pFlagAry [nPoints - nCount], 0, nCount );
nPoints = nPoints - nCount; nPoints = nPoints - nCount;
} }
...@@ -195,7 +198,7 @@ void ImpXPolygon::CheckPointDelete() const ...@@ -195,7 +198,7 @@ void ImpXPolygon::CheckPointDelete() const
{ {
if ( bDeleteOldPoints ) if ( bDeleteOldPoints )
{ {
delete[] reinterpret_cast<char*>(pOldPointAry); delete[] pOldPointAry;
const_cast< ImpXPolygon* >(this)->pOldPointAry = nullptr; const_cast< ImpXPolygon* >(this)->pOldPointAry = nullptr;
const_cast< ImpXPolygon* >(this)->bDeleteOldPoints = false; const_cast< ImpXPolygon* >(this)->bDeleteOldPoints = false;
} }
...@@ -344,7 +347,8 @@ void XPolygon::SetPointCount( sal_uInt16 nPoints ) ...@@ -344,7 +347,8 @@ void XPolygon::SetPointCount( sal_uInt16 nPoints )
if ( nPoints < pImpXPolygon->nPoints ) if ( nPoints < pImpXPolygon->nPoints )
{ {
sal_uInt16 nSize = pImpXPolygon->nPoints - nPoints; sal_uInt16 nSize = pImpXPolygon->nPoints - nPoints;
memset( &pImpXPolygon->pPointAry[nPoints], 0, nSize * sizeof( Point ) ); std::fill(
pImpXPolygon->pPointAry + nPoints, pImpXPolygon->pPointAry + nPoints + nSize, Point());
memset( &pImpXPolygon->pFlagAry [nPoints], 0, nSize ); memset( &pImpXPolygon->pFlagAry [nPoints], 0, nSize );
} }
pImpXPolygon->nPoints = nPoints; pImpXPolygon->nPoints = nPoints;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment