diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-12-07 14:37:56 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-12-07 17:46:23 +0100 |
commit | 5de20e45e48f7654d288f26f768fabddad133bfd (patch) | |
tree | cce410ce740ae0ca760855a2ddc2ca09d623e633 /basegfx | |
parent | 7e8e57a456f2b946631eecefd163cb4ff3a3d603 (diff) |
improve loplugin:cow_wrapper
to find my previous attempt at this, which only obscured the problem
<noelgrandin> I'm such an idiot
<noelgrandin> I changed a whole bunch of code to avoid calling const
methods on a non-const object
<noelgrandin> from p->foo() to std::as_const(*p).foo()
<noelgrandin> can you spot the mistake?
<bubli> Is this a job interview question? :D
<vmiklos> noelgrandin: you did the opposite, now you always call const
member functions, while you wanted to always call non-const member
functions?
<noelgrandin> more like a "why didn't the smart people on this channel
tell me I was an idiot" :-)
<noelgrandin> in this case, we have o3tl::cow_wrapper, which overrides
operator* and operator->
<vmiklos> ah, and by the time you would add/remove the const,
cow_wrapper already did the expensive task of copying based on
const/non-const
<noelgrandin> exactly
<thorsten> heh
Change-Id: I5366e6a87c414b862668b61e6adfbccfdd9d3b04
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126473
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'basegfx')
-rw-r--r-- | basegfx/source/polygon/b2dpolygon.cxx | 52 | ||||
-rw-r--r-- | basegfx/source/polygon/b2dpolypolygon.cxx | 16 | ||||
-rw-r--r-- | basegfx/source/polygon/b3dpolygon.cxx | 34 | ||||
-rw-r--r-- | basegfx/source/polygon/b3dpolypolygon.cxx | 10 |
4 files changed, 56 insertions, 56 deletions
diff --git a/basegfx/source/polygon/b2dpolygon.cxx b/basegfx/source/polygon/b2dpolygon.cxx index a1d50321e8e9..4d2b681911e2 100644 --- a/basegfx/source/polygon/b2dpolygon.cxx +++ b/basegfx/source/polygon/b2dpolygon.cxx @@ -1177,9 +1177,9 @@ namespace basegfx void B2DPolygon::setB2DPoint(sal_uInt32 nIndex, const B2DPoint& rValue) { - OSL_ENSURE(nIndex < std::as_const(*mpPolygon).count(), "B2DPolygon access outside range (!)"); + OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B2DPolygon access outside range (!)"); - if(std::as_const(*mpPolygon).getPoint(nIndex) != rValue) + if(std::as_const(mpPolygon)->getPoint(nIndex) != rValue) { mpPolygon->setPoint(nIndex, rValue); } @@ -1192,7 +1192,7 @@ namespace basegfx void B2DPolygon::insert(sal_uInt32 nIndex, const B2DPoint& rPoint, sal_uInt32 nCount) { - OSL_ENSURE(nIndex <= std::as_const(*mpPolygon).count(), "B2DPolygon Insert outside range (!)"); + OSL_ENSURE(nIndex <= std::as_const(mpPolygon)->count(), "B2DPolygon Insert outside range (!)"); if(nCount) { @@ -1204,7 +1204,7 @@ namespace basegfx { if(nCount) { - mpPolygon->insert(std::as_const(*mpPolygon).count(), rPoint, nCount); + mpPolygon->insert(std::as_const(mpPolygon)->count(), rPoint, nCount); } } @@ -1243,10 +1243,10 @@ namespace basegfx void B2DPolygon::setPrevControlPoint(sal_uInt32 nIndex, const B2DPoint& rValue) { - OSL_ENSURE(nIndex < std::as_const(*mpPolygon).count(), "B2DPolygon access outside range (!)"); - const basegfx::B2DVector aNewVector(rValue - std::as_const(*mpPolygon).getPoint(nIndex)); + OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B2DPolygon access outside range (!)"); + const basegfx::B2DVector aNewVector(rValue - std::as_const(mpPolygon)->getPoint(nIndex)); - if(std::as_const(*mpPolygon).getPrevControlVector(nIndex) != aNewVector) + if(std::as_const(mpPolygon)->getPrevControlVector(nIndex) != aNewVector) { mpPolygon->setPrevControlVector(nIndex, aNewVector); } @@ -1254,10 +1254,10 @@ namespace basegfx void B2DPolygon::setNextControlPoint(sal_uInt32 nIndex, const B2DPoint& rValue) { - OSL_ENSURE(nIndex < std::as_const(*mpPolygon).count(), "B2DPolygon access outside range (!)"); - const basegfx::B2DVector aNewVector(rValue - std::as_const(*mpPolygon).getPoint(nIndex)); + OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B2DPolygon access outside range (!)"); + const basegfx::B2DVector aNewVector(rValue - std::as_const(mpPolygon)->getPoint(nIndex)); - if(std::as_const(*mpPolygon).getNextControlVector(nIndex) != aNewVector) + if(std::as_const(mpPolygon)->getNextControlVector(nIndex) != aNewVector) { mpPolygon->setNextControlVector(nIndex, aNewVector); } @@ -1265,12 +1265,12 @@ namespace basegfx void B2DPolygon::setControlPoints(sal_uInt32 nIndex, const basegfx::B2DPoint& rPrev, const basegfx::B2DPoint& rNext) { - OSL_ENSURE(nIndex < std::as_const(*mpPolygon).count(), "B2DPolygon access outside range (!)"); - const B2DPoint aPoint(std::as_const(*mpPolygon).getPoint(nIndex)); + OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B2DPolygon access outside range (!)"); + const B2DPoint aPoint(std::as_const(mpPolygon)->getPoint(nIndex)); const basegfx::B2DVector aNewPrev(rPrev - aPoint); const basegfx::B2DVector aNewNext(rNext - aPoint); - if(std::as_const(*mpPolygon).getPrevControlVector(nIndex) != aNewPrev || std::as_const(*mpPolygon).getNextControlVector(nIndex) != aNewNext) + if(std::as_const(mpPolygon)->getPrevControlVector(nIndex) != aNewPrev || std::as_const(mpPolygon)->getNextControlVector(nIndex) != aNewNext) { mpPolygon->setControlVectors(nIndex, aNewPrev, aNewNext); } @@ -1278,9 +1278,9 @@ namespace basegfx void B2DPolygon::resetPrevControlPoint(sal_uInt32 nIndex) { - OSL_ENSURE(nIndex < std::as_const(*mpPolygon).count(), "B2DPolygon access outside range (!)"); + OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B2DPolygon access outside range (!)"); - if(std::as_const(*mpPolygon).areControlPointsUsed() && !std::as_const(*mpPolygon).getPrevControlVector(nIndex).equalZero()) + if(std::as_const(mpPolygon)->areControlPointsUsed() && !std::as_const(mpPolygon)->getPrevControlVector(nIndex).equalZero()) { mpPolygon->setPrevControlVector(nIndex, B2DVector::getEmptyVector()); } @@ -1288,9 +1288,9 @@ namespace basegfx void B2DPolygon::resetNextControlPoint(sal_uInt32 nIndex) { - OSL_ENSURE(nIndex < std::as_const(*mpPolygon).count(), "B2DPolygon access outside range (!)"); + OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B2DPolygon access outside range (!)"); - if(std::as_const(*mpPolygon).areControlPointsUsed() && !std::as_const(*mpPolygon).getNextControlVector(nIndex).equalZero()) + if(std::as_const(mpPolygon)->areControlPointsUsed() && !std::as_const(mpPolygon)->getNextControlVector(nIndex).equalZero()) { mpPolygon->setNextControlVector(nIndex, B2DVector::getEmptyVector()); } @@ -1298,7 +1298,7 @@ namespace basegfx void B2DPolygon::resetControlPoints() { - if(std::as_const(*mpPolygon).areControlPointsUsed()) + if(std::as_const(mpPolygon)->areControlPointsUsed()) { mpPolygon->resetControlVectors(); } @@ -1309,12 +1309,12 @@ namespace basegfx const B2DPoint& rPrevControlPoint, const B2DPoint& rPoint) { - const B2DVector aNewNextVector(std::as_const(*mpPolygon).count() ? B2DVector(rNextControlPoint - std::as_const(*mpPolygon).getPoint(std::as_const(*mpPolygon).count() - 1)) : B2DVector::getEmptyVector()); + const B2DVector aNewNextVector(std::as_const(mpPolygon)->count() ? B2DVector(rNextControlPoint - std::as_const(mpPolygon)->getPoint(std::as_const(mpPolygon)->count() - 1)) : B2DVector::getEmptyVector()); const B2DVector aNewPrevVector(rPrevControlPoint - rPoint); if(aNewNextVector.equalZero() && aNewPrevVector.equalZero()) { - mpPolygon->insert(std::as_const(*mpPolygon).count(), rPoint, 1); + mpPolygon->insert(std::as_const(mpPolygon)->count(), rPoint, 1); } else { @@ -1324,7 +1324,7 @@ namespace basegfx void B2DPolygon::appendQuadraticBezierSegment(const B2DPoint& rControlPoint, const B2DPoint& rPoint) { - if (std::as_const(*mpPolygon).count() == 0) + if (std::as_const(mpPolygon)->count() == 0) { mpPolygon->append(rPoint); const double nX((rControlPoint.getX() * 2.0 + rPoint.getX()) / 3.0); @@ -1333,7 +1333,7 @@ namespace basegfx } else { - const B2DPoint aPreviousPoint(std::as_const(*mpPolygon).getPoint(std::as_const(*mpPolygon).count() - 1)); + const B2DPoint aPreviousPoint(std::as_const(mpPolygon)->getPoint(std::as_const(mpPolygon)->count() - 1)); const double nX1((rControlPoint.getX() * 2.0 + aPreviousPoint.getX()) / 3.0); const double nY1((rControlPoint.getY() * 2.0 + aPreviousPoint.getY()) / 3.0); @@ -1436,19 +1436,19 @@ namespace basegfx if(nIndex == 0 && nCount == rPoly.count()) { - mpPolygon->insert(std::as_const(*mpPolygon).count(), *rPoly.mpPolygon); + mpPolygon->insert(std::as_const(mpPolygon)->count(), *rPoly.mpPolygon); } else { OSL_ENSURE(nIndex + nCount <= rPoly.mpPolygon->count(), "B2DPolygon Append outside range (!)"); ImplB2DPolygon aTempPoly(*rPoly.mpPolygon, nIndex, nCount); - mpPolygon->insert(std::as_const(*mpPolygon).count(), aTempPoly); + mpPolygon->insert(std::as_const(mpPolygon)->count(), aTempPoly); } } void B2DPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) { - OSL_ENSURE(nIndex + nCount <= std::as_const(*mpPolygon).count(), "B2DPolygon Remove outside range (!)"); + OSL_ENSURE(nIndex + nCount <= std::as_const(mpPolygon)->count(), "B2DPolygon Remove outside range (!)"); if(nCount) { @@ -1498,7 +1498,7 @@ namespace basegfx void B2DPolygon::transform(const B2DHomMatrix& rMatrix) { - if(std::as_const(*mpPolygon).count() && !rMatrix.isIdentity()) + if(std::as_const(mpPolygon)->count() && !rMatrix.isIdentity()) { mpPolygon->transform(rMatrix); } diff --git a/basegfx/source/polygon/b2dpolypolygon.cxx b/basegfx/source/polygon/b2dpolypolygon.cxx index 34ff30877ea8..13724164ff2f 100644 --- a/basegfx/source/polygon/b2dpolypolygon.cxx +++ b/basegfx/source/polygon/b2dpolypolygon.cxx @@ -249,7 +249,7 @@ namespace basegfx void B2DPolyPolygon::setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon& rPolygon) { - OSL_ENSURE(nIndex < std::as_const(*mpPolyPolygon).count(), "B2DPolyPolygon access outside range (!)"); + OSL_ENSURE(nIndex < std::as_const(mpPolyPolygon)->count(), "B2DPolyPolygon access outside range (!)"); if(getB2DPolygon(nIndex) != rPolygon) mpPolyPolygon->setB2DPolygon(nIndex, rPolygon); @@ -272,7 +272,7 @@ namespace basegfx void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolygon& rPolygon, sal_uInt32 nCount) { - OSL_ENSURE(nIndex <= std::as_const(*mpPolyPolygon).count(), "B2DPolyPolygon Insert outside range (!)"); + OSL_ENSURE(nIndex <= std::as_const(mpPolyPolygon)->count(), "B2DPolyPolygon Insert outside range (!)"); if(nCount) mpPolyPolygon->insert(nIndex, rPolygon, nCount); @@ -281,7 +281,7 @@ namespace basegfx void B2DPolyPolygon::append(const B2DPolygon& rPolygon, sal_uInt32 nCount) { if(nCount) - mpPolyPolygon->insert(std::as_const(*mpPolyPolygon).count(), rPolygon, nCount); + mpPolyPolygon->insert(std::as_const(mpPolyPolygon)->count(), rPolygon, nCount); } B2DPolyPolygon B2DPolyPolygon::getDefaultAdaptiveSubdivision() const @@ -310,7 +310,7 @@ namespace basegfx void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolyPolygon& rPolyPolygon) { - OSL_ENSURE(nIndex <= std::as_const(*mpPolyPolygon).count(), "B2DPolyPolygon Insert outside range (!)"); + OSL_ENSURE(nIndex <= std::as_const(mpPolyPolygon)->count(), "B2DPolyPolygon Insert outside range (!)"); if(rPolyPolygon.count()) mpPolyPolygon->insert(nIndex, rPolyPolygon); @@ -319,12 +319,12 @@ namespace basegfx void B2DPolyPolygon::append(const B2DPolyPolygon& rPolyPolygon) { if(rPolyPolygon.count()) - mpPolyPolygon->insert(std::as_const(*mpPolyPolygon).count(), rPolyPolygon); + mpPolyPolygon->insert(std::as_const(mpPolyPolygon)->count(), rPolyPolygon); } void B2DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) { - OSL_ENSURE(nIndex + nCount <= std::as_const(*mpPolyPolygon).count(), "B2DPolyPolygon Remove outside range (!)"); + OSL_ENSURE(nIndex + nCount <= std::as_const(mpPolyPolygon)->count(), "B2DPolyPolygon Remove outside range (!)"); if(nCount) mpPolyPolygon->remove(nIndex, nCount); @@ -360,7 +360,7 @@ namespace basegfx void B2DPolyPolygon::flip() { - if(std::as_const(*mpPolyPolygon).count()) + if(std::as_const(mpPolyPolygon)->count()) { mpPolyPolygon->flip(); } @@ -389,7 +389,7 @@ namespace basegfx void B2DPolyPolygon::transform(const B2DHomMatrix& rMatrix) { - if(std::as_const(*mpPolyPolygon).count() && !rMatrix.isIdentity()) + if(std::as_const(mpPolyPolygon)->count() && !rMatrix.isIdentity()) { mpPolyPolygon->transform(rMatrix); } diff --git a/basegfx/source/polygon/b3dpolygon.cxx b/basegfx/source/polygon/b3dpolygon.cxx index dac943c79049..a14b9f3887b8 100644 --- a/basegfx/source/polygon/b3dpolygon.cxx +++ b/basegfx/source/polygon/b3dpolygon.cxx @@ -1431,7 +1431,7 @@ namespace basegfx void B3DPolygon::setB3DPoint(sal_uInt32 nIndex, const basegfx::B3DPoint& rValue) { - OSL_ENSURE(nIndex < std::as_const(*mpPolygon).count(), "B3DPolygon access outside range (!)"); + OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B3DPolygon access outside range (!)"); if(getB3DPoint(nIndex) != rValue) mpPolygon->setPoint(nIndex, rValue); @@ -1446,9 +1446,9 @@ namespace basegfx void B3DPolygon::setBColor(sal_uInt32 nIndex, const BColor& rValue) { - OSL_ENSURE(nIndex < std::as_const(*mpPolygon).count(), "B3DPolygon access outside range (!)"); + OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B3DPolygon access outside range (!)"); - if(std::as_const(*mpPolygon).getBColor(nIndex) != rValue) + if(std::as_const(mpPolygon)->getBColor(nIndex) != rValue) mpPolygon->setBColor(nIndex, rValue); } @@ -1459,7 +1459,7 @@ namespace basegfx void B3DPolygon::clearBColors() { - if(std::as_const(*mpPolygon).areBColorsUsed()) + if(std::as_const(mpPolygon)->areBColorsUsed()) mpPolygon->clearBColors(); } @@ -1477,15 +1477,15 @@ namespace basegfx void B3DPolygon::setNormal(sal_uInt32 nIndex, const B3DVector& rValue) { - OSL_ENSURE(nIndex < std::as_const(*mpPolygon).count(), "B3DPolygon access outside range (!)"); + OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B3DPolygon access outside range (!)"); - if(std::as_const(*mpPolygon).getNormal(nIndex) != rValue) + if(std::as_const(mpPolygon)->getNormal(nIndex) != rValue) mpPolygon->setNormal(nIndex, rValue); } void B3DPolygon::transformNormals(const B3DHomMatrix& rMatrix) { - if(std::as_const(*mpPolygon).areNormalsUsed() && !rMatrix.isIdentity()) + if(std::as_const(mpPolygon)->areNormalsUsed() && !rMatrix.isIdentity()) mpPolygon->transformNormals(rMatrix); } @@ -1496,7 +1496,7 @@ namespace basegfx void B3DPolygon::clearNormals() { - if(std::as_const(*mpPolygon).areNormalsUsed()) + if(std::as_const(mpPolygon)->areNormalsUsed()) mpPolygon->clearNormals(); } @@ -1509,15 +1509,15 @@ namespace basegfx void B3DPolygon::setTextureCoordinate(sal_uInt32 nIndex, const B2DPoint& rValue) { - OSL_ENSURE(nIndex < std::as_const(*mpPolygon).count(), "B3DPolygon access outside range (!)"); + OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B3DPolygon access outside range (!)"); - if(std::as_const(*mpPolygon).getTextureCoordinate(nIndex) != rValue) + if(std::as_const(mpPolygon)->getTextureCoordinate(nIndex) != rValue) mpPolygon->setTextureCoordinate(nIndex, rValue); } void B3DPolygon::transformTextureCoordinates(const B2DHomMatrix& rMatrix) { - if(std::as_const(*mpPolygon).areTextureCoordinatesUsed() && !rMatrix.isIdentity()) + if(std::as_const(mpPolygon)->areTextureCoordinatesUsed() && !rMatrix.isIdentity()) mpPolygon->transformTextureCoordinates(rMatrix); } @@ -1528,14 +1528,14 @@ namespace basegfx void B3DPolygon::clearTextureCoordinates() { - if(std::as_const(*mpPolygon).areTextureCoordinatesUsed()) + if(std::as_const(mpPolygon)->areTextureCoordinatesUsed()) mpPolygon->clearTextureCoordinates(); } void B3DPolygon::append(const basegfx::B3DPoint& rPoint, sal_uInt32 nCount) { if(nCount) - mpPolygon->insert(std::as_const(*mpPolygon).count(), rPoint, nCount); + mpPolygon->insert(std::as_const(mpPolygon)->count(), rPoint, nCount); } void B3DPolygon::append(const B3DPolygon& rPoly, sal_uInt32 nIndex, sal_uInt32 nCount) @@ -1550,19 +1550,19 @@ namespace basegfx if(nIndex == 0 && nCount == rPoly.count()) { - mpPolygon->insert(std::as_const(*mpPolygon).count(), *rPoly.mpPolygon); + mpPolygon->insert(std::as_const(mpPolygon)->count(), *rPoly.mpPolygon); } else { OSL_ENSURE(nIndex + nCount <= rPoly.mpPolygon->count(), "B3DPolygon Append outside range (!)"); ImplB3DPolygon aTempPoly(*rPoly.mpPolygon, nIndex, nCount); - mpPolygon->insert(std::as_const(*mpPolygon).count(), aTempPoly); + mpPolygon->insert(std::as_const(mpPolygon)->count(), aTempPoly); } } void B3DPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) { - OSL_ENSURE(nIndex + nCount <= std::as_const(*mpPolygon).count(), "B3DPolygon Remove outside range (!)"); + OSL_ENSURE(nIndex + nCount <= std::as_const(mpPolygon)->count(), "B3DPolygon Remove outside range (!)"); if(nCount) mpPolygon->remove(nIndex, nCount); @@ -1606,7 +1606,7 @@ namespace basegfx void B3DPolygon::transform(const basegfx::B3DHomMatrix& rMatrix) { - if(std::as_const(*mpPolygon).count() && !rMatrix.isIdentity()) + if(std::as_const(mpPolygon)->count() && !rMatrix.isIdentity()) { mpPolygon->transform(rMatrix); } diff --git a/basegfx/source/polygon/b3dpolypolygon.cxx b/basegfx/source/polygon/b3dpolypolygon.cxx index 4104d2fc29fe..e7334af42874 100644 --- a/basegfx/source/polygon/b3dpolypolygon.cxx +++ b/basegfx/source/polygon/b3dpolypolygon.cxx @@ -241,7 +241,7 @@ namespace basegfx void B3DPolyPolygon::setB3DPolygon(sal_uInt32 nIndex, const B3DPolygon& rPolygon) { - OSL_ENSURE(nIndex < std::as_const(*mpPolyPolygon).count(), "B3DPolyPolygon access outside range (!)"); + OSL_ENSURE(nIndex < std::as_const(mpPolyPolygon)->count(), "B3DPolyPolygon access outside range (!)"); if(getB3DPolygon(nIndex) != rPolygon) mpPolyPolygon->setB3DPolygon(nIndex, rPolygon); @@ -319,18 +319,18 @@ namespace basegfx void B3DPolyPolygon::append(const B3DPolygon& rPolygon, sal_uInt32 nCount) { if(nCount) - mpPolyPolygon->insert(std::as_const(*mpPolyPolygon).count(), rPolygon, nCount); + mpPolyPolygon->insert(std::as_const(mpPolyPolygon)->count(), rPolygon, nCount); } void B3DPolyPolygon::append(const B3DPolyPolygon& rPolyPolygon) { if(rPolyPolygon.count()) - mpPolyPolygon->insert(std::as_const(*mpPolyPolygon).count(), rPolyPolygon); + mpPolyPolygon->insert(std::as_const(mpPolyPolygon)->count(), rPolyPolygon); } void B3DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) { - OSL_ENSURE(nIndex + nCount <= std::as_const(*mpPolyPolygon).count(), "B3DPolyPolygon Remove outside range (!)"); + OSL_ENSURE(nIndex + nCount <= std::as_const(mpPolyPolygon)->count(), "B3DPolyPolygon Remove outside range (!)"); if(nCount) mpPolyPolygon->remove(nIndex, nCount); @@ -369,7 +369,7 @@ namespace basegfx void B3DPolyPolygon::transform(const B3DHomMatrix& rMatrix) { - if(std::as_const(*mpPolyPolygon).count() && !rMatrix.isIdentity()) + if(std::as_const(mpPolyPolygon)->count() && !rMatrix.isIdentity()) { mpPolyPolygon->transform(rMatrix); } |