basegfx/source/polygon/b2dpolypolygon.cxx |   16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

New commits:
commit e4a72aa946b6c41a91dc6e74634093a83b9c22bd
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Sep 20 18:28:36 2022 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Tue Sep 20 21:20:08 2022 +0200

    tdf#151056: avoid modifying the static shared DEFAULT instance
    
    This was a thinko in commit e39fa3c4f5ae2560a4b6f6f789a0c5098ac43cf4
      Simplify b2d(poly)polygon implementation
    
    This led to exponential growth of elements in each next polypolygon
    created from scratch, that immediately manifested with the complex
    SVG logo shown on the backing window.
    And finally, there's no const_cast/as_const left in the file :)
    
    Change-Id: Ie60f75ec86a8fa21799f4f1b589c04c9e4646183
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140248
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/basegfx/source/polygon/b2dpolypolygon.cxx 
b/basegfx/source/polygon/b2dpolypolygon.cxx
index 6ce3b398a1fb..1889ddae4220 100644
--- a/basegfx/source/polygon/b2dpolypolygon.cxx
+++ b/basegfx/source/polygon/b2dpolypolygon.cxx
@@ -299,13 +299,17 @@ public:
     B2DPolyPolygon B2DPolyPolygon::getDefaultAdaptiveSubdivision() const
     {
         B2DPolyPolygon aRetval;
-        // Avoid CoW overhead for the local variable
-        auto dest = 
const_cast<ImplB2DPolyPolygon*>(std::as_const(aRetval).mpPolyPolygon.get());
-        dest->reserve(count());
-
-        for(sal_uInt32 a(0); a < count(); a++)
+        if (count())
         {
-            dest->append(getB2DPolygon(a).getDefaultAdaptiveSubdivision(), 1);
+            // Avoid CoW overhead for the local variable
+            // But detach from shared static DEFAULT
+            ImplB2DPolyPolygon& dest = aRetval.mpPolyPolygon.make_unique();
+            dest.reserve(count());
+
+            for (sal_uInt32 a(0); a < count(); a++)
+            {
+                dest.append(getB2DPolygon(a).getDefaultAdaptiveSubdivision(), 
1);
+            }
         }
 
         return aRetval;

Reply via email to