basegfx/source/polygon/b2dpolygon.cxx | 58 +++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-)
New commits: commit 9686a654506999a806a51ee1a13c871be4ba27a0 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sun Sep 1 09:13:06 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sun Sep 1 12:39:13 2024 +0200 avoid intermediate copy in B2DPolygon::append Change-Id: If187028195afcef42f9171f54651ada35bf3be4e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172708 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/basegfx/source/polygon/b2dpolygon.cxx b/basegfx/source/polygon/b2dpolygon.cxx index b54570df36ac..dabca6674f8f 100644 --- a/basegfx/source/polygon/b2dpolygon.cxx +++ b/basegfx/source/polygon/b2dpolygon.cxx @@ -100,6 +100,16 @@ public: maVector.insert(aIndex, aStart, aEnd); } + void insert(sal_uInt32 nIndex, const CoordinateDataArray2D& rSource, sal_uInt32 nSourceIndex, sal_uInt32 nSourceCount) + { + // insert data + auto aIndex = maVector.begin(); + aIndex += nIndex; + auto aStart = rSource.maVector.cbegin() + nSourceIndex; + auto aEnd = rSource.maVector.cbegin() + nSourceIndex + nSourceCount; + maVector.insert(aIndex, aStart, aEnd); + } + void remove(sal_uInt32 nIndex, sal_uInt32 nCount) { assert(nCount > 0); @@ -365,6 +375,27 @@ public: } } + void insert(sal_uInt32 nIndex, const ControlVectorArray2D& rSource, sal_uInt32 nSourceIndex, sal_uInt32 nSourceCount) + { + assert(rSource.maVector.size() > 0); + assert(nIndex + nSourceCount <= maVector.size()); + + // insert data + ControlVectorPair2DVector::iterator aIndex(maVector.begin() + nIndex); + ControlVectorPair2DVector::const_iterator aStart(rSource.maVector.begin() + nSourceIndex); + ControlVectorPair2DVector::const_iterator aEnd(rSource.maVector.begin() + nSourceIndex + nSourceCount); + maVector.insert(aIndex, aStart, aEnd); + + for(; aStart != aEnd; ++aStart) + { + if(!aStart->getPrevVector().equalZero()) + mnUsedVectors++; + + if(!aStart->getNextVector().equalZero()) + mnUsedVectors++; + } + } + void remove(sal_uInt32 nIndex, sal_uInt32 nCount) { assert(nCount > 0); @@ -807,6 +838,31 @@ public: setPrevControlVector(nCount, rPrev); } + void append(const ImplB2DPolygon& rSource, sal_uInt32 nSourceIndex, sal_uInt32 nSourceCount) + { + assert(rSource.maPoints.count() > 0); + const sal_uInt32 nIndex = count(); + + mpBufferedData.reset(); + + maPoints.insert(nIndex, rSource.maPoints, nSourceIndex, nSourceCount); + + if(rSource.moControlVector && rSource.moControlVector->isUsed()) + { + if (!moControlVector) + moControlVector.emplace(nIndex); + moControlVector->insert(nIndex, *rSource.moControlVector, nSourceIndex, nSourceCount); + + if(!moControlVector->isUsed()) + moControlVector.reset(); + } + else if(moControlVector) + { + ControlVectorPair2D aVectorPair; + moControlVector->insert(nIndex, aVectorPair, rSource.count()); + } + } + void append(const ImplB2DPolygon& rSource) { assert(rSource.maPoints.count() > 0); @@ -1378,7 +1434,7 @@ namespace basegfx } else { - mpPolygon->append(ImplB2DPolygon(*rPoly.mpPolygon, nIndex, nCount)); + mpPolygon->append(*rPoly.mpPolygon, nIndex, nCount); } }