[Libreoffice-commits] .: 2 commits - basegfx/inc basegfx/source basegfx/test
Thorsten Behrens
thorsten at kemper.freedesktop.org
Tue Dec 13 11:59:25 PST 2011
basegfx/inc/basegfx/polygon/b2dpolygon.hxx | 6 --
basegfx/inc/basegfx/polygon/b3dpolypolygon.hxx | 6 ++
basegfx/source/polygon/b2dpolygon.cxx | 19 ------
basegfx/source/polygon/b2dpolypolygon.cxx | 6 +-
basegfx/source/polygon/b3dpolypolygon.cxx | 73 +++++++++++++++++++------
basegfx/test/boxclipper.cxx | 17 ++++-
6 files changed, 80 insertions(+), 47 deletions(-)
New commits:
commit 23c16ec47cec92566b426168ed53c795116b56f6
Author: Thorsten Behrens <tbehrens at suse.com>
Date: Tue Dec 13 20:56:17 2011 +0100
Fix abort from stl debug iterators' invalid access.
Triggered by fdo#43725, incrementing an invalid iterator bombs -
though this seems a corner case, depends on whether one considers
"+= 0" as incrementing or not.
diff --git a/basegfx/source/polygon/b2dpolypolygon.cxx b/basegfx/source/polygon/b2dpolypolygon.cxx
index bdd619f..3ec0ed8 100644
--- a/basegfx/source/polygon/b2dpolypolygon.cxx
+++ b/basegfx/source/polygon/b2dpolypolygon.cxx
@@ -84,7 +84,8 @@ public:
{
// add nCount copies of rPolygon
PolygonVector::iterator aIndex(maPolygons.begin());
- aIndex += nIndex;
+ if( nIndex )
+ aIndex += nIndex;
maPolygons.insert(aIndex, nCount, rPolygon);
}
}
@@ -93,7 +94,8 @@ public:
{
// add all polygons from rPolyPolygon
PolygonVector::iterator aIndex(maPolygons.begin());
- aIndex += nIndex;
+ if( nIndex )
+ aIndex += nIndex;
maPolygons.insert(aIndex, rPolyPolygon.begin(), rPolyPolygon.end());
}
diff --git a/basegfx/source/polygon/b3dpolypolygon.cxx b/basegfx/source/polygon/b3dpolypolygon.cxx
index cbd59b6..be1db5e 100644
--- a/basegfx/source/polygon/b3dpolypolygon.cxx
+++ b/basegfx/source/polygon/b3dpolypolygon.cxx
@@ -83,7 +83,8 @@ public:
{
// add nCount copies of rPolygon
PolygonVector::iterator aIndex(maPolygons.begin());
- aIndex += nIndex;
+ if( nIndex )
+ aIndex += nIndex;
maPolygons.insert(aIndex, nCount, rPolygon);
}
}
@@ -92,7 +93,8 @@ public:
{
// add all polygons from rPolyPolygon
PolygonVector::iterator aIndex(maPolygons.begin());
- aIndex += nIndex;
+ if( nIndex )
+ aIndex += nIndex;
maPolygons.insert(aIndex, rPolyPolygon.begin(), rPolyPolygon.end());
}
commit 7b7c3b6e1102e7f8856f047fe475ddbc53438f4e
Author: Thorsten Behrens <tbehrens at suse.com>
Date: Tue Dec 13 19:18:39 2011 +0100
More efficient insertion of B3DPolygons
* some cleanup - removed ugly-as-hell exposure of only parts of the
internal data struct on B2DPolygon (and reworked the only client
of that code)
* added stl-style begin/end to B3DPolyPolygon as well, mirroring
B2DPolyPolygon, plus adapting the insert() func to make use of
that (avoiding loads of temporaries)
diff --git a/basegfx/inc/basegfx/polygon/b2dpolygon.hxx b/basegfx/inc/basegfx/polygon/b2dpolygon.hxx
index 694531c..da23bb4 100644
--- a/basegfx/inc/basegfx/polygon/b2dpolygon.hxx
+++ b/basegfx/inc/basegfx/polygon/b2dpolygon.hxx
@@ -262,12 +262,6 @@ namespace basegfx
/// apply transformation given in matrix form
void transform(const basegfx::B2DHomMatrix& rMatrix);
-
- // point iterators (same iterator validity conditions as for vector)
- const B2DPoint* begin() const;
- const B2DPoint* end() const;
- B2DPoint* begin();
- B2DPoint* end();
};
} // end of namespace basegfx
diff --git a/basegfx/inc/basegfx/polygon/b3dpolypolygon.hxx b/basegfx/inc/basegfx/polygon/b3dpolypolygon.hxx
index ffcc4f2..1964e5f 100644
--- a/basegfx/inc/basegfx/polygon/b3dpolypolygon.hxx
+++ b/basegfx/inc/basegfx/polygon/b3dpolypolygon.hxx
@@ -121,6 +121,12 @@ namespace basegfx
// apply transformation given in matrix form to the polygon
void transform(const basegfx::B3DHomMatrix& rMatrix);
+
+ // polygon iterators (same iterator validity conditions as for vector)
+ const B3DPolygon* begin() const;
+ const B3DPolygon* end() const;
+ B3DPolygon* begin();
+ B3DPolygon* end();
};
} // end of namespace basegfx
diff --git a/basegfx/source/polygon/b2dpolygon.cxx b/basegfx/source/polygon/b2dpolygon.cxx
index e9bbb97..3bc0401 100644
--- a/basegfx/source/polygon/b2dpolygon.cxx
+++ b/basegfx/source/polygon/b2dpolygon.cxx
@@ -1628,25 +1628,6 @@ namespace basegfx
}
}
- const B2DPoint* B2DPolygon::begin() const
- {
- return mpPolygon->begin();
- }
-
- const B2DPoint* B2DPolygon::end() const
- {
- return mpPolygon->end();
- }
-
- B2DPoint* B2DPolygon::begin()
- {
- return mpPolygon->begin();
- }
-
- B2DPoint* B2DPolygon::end()
- {
- return mpPolygon->end();
- }
} // end of namespace basegfx
//////////////////////////////////////////////////////////////////////////////
diff --git a/basegfx/source/polygon/b3dpolypolygon.cxx b/basegfx/source/polygon/b3dpolypolygon.cxx
index 3bdd9c3..cbd59b6 100644
--- a/basegfx/source/polygon/b3dpolypolygon.cxx
+++ b/basegfx/source/polygon/b3dpolypolygon.cxx
@@ -90,21 +90,10 @@ public:
void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolyPolygon& rPolyPolygon)
{
- const sal_uInt32 nCount = rPolyPolygon.count();
-
- if(nCount)
- {
- // add nCount polygons from rPolyPolygon
- maPolygons.reserve(maPolygons.size() + nCount);
- PolygonVector::iterator aIndex(maPolygons.begin());
- aIndex += nIndex;
-
- for(sal_uInt32 a(0L); a < nCount; a++)
- {
- maPolygons.insert(aIndex, rPolyPolygon.getB3DPolygon(a));
- aIndex++;
- }
- }
+ // add all polygons from rPolyPolygon
+ PolygonVector::iterator aIndex(maPolygons.begin());
+ aIndex += nIndex;
+ maPolygons.insert(aIndex, rPolyPolygon.begin(), rPolyPolygon.end());
}
void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
@@ -201,6 +190,38 @@ public:
maPolygons.end(),
std::mem_fun_ref( &::basegfx::B3DPolygon::makeUnique ));
}
+
+ const basegfx::B3DPolygon* begin() const
+ {
+ if(maPolygons.empty())
+ return 0;
+ else
+ return &maPolygons.front();
+ }
+
+ const basegfx::B3DPolygon* end() const
+ {
+ if(maPolygons.empty())
+ return 0;
+ else
+ return (&maPolygons.back())+1;
+ }
+
+ basegfx::B3DPolygon* begin()
+ {
+ if(maPolygons.empty())
+ return 0;
+ else
+ return &maPolygons.front();
+ }
+
+ basegfx::B3DPolygon* end()
+ {
+ if(maPolygons.empty())
+ return 0;
+ else
+ return &(maPolygons.back())+1;
+ }
};
//////////////////////////////////////////////////////////////////////////////
@@ -440,6 +461,26 @@ namespace basegfx
mpPolyPolygon->transform(rMatrix);
}
}
+
+ const B3DPolygon* B3DPolyPolygon::begin() const
+ {
+ return mpPolyPolygon->begin();
+ }
+
+ const B3DPolygon* B3DPolyPolygon::end() const
+ {
+ return mpPolyPolygon->end();
+ }
+
+ B3DPolygon* B3DPolyPolygon::begin()
+ {
+ return mpPolyPolygon->begin();
+ }
+
+ B3DPolygon* B3DPolyPolygon::end()
+ {
+ return mpPolyPolygon->end();
+ }
} // end of namespace basegfx
// eof
diff --git a/basegfx/test/boxclipper.cxx b/basegfx/test/boxclipper.cxx
index 05cbb7b..20a17b0 100644
--- a/basegfx/test/boxclipper.cxx
+++ b/basegfx/test/boxclipper.cxx
@@ -206,18 +206,25 @@ public:
aTmp.flip();
aTmp=tools::removeNeutralPoints(aTmp);
+ std::vector<B2DPoint> aTmp2(aTmp.count());
+ for(sal_uInt32 j=0; j<aTmp.count(); ++j)
+ aTmp2[j] = aTmp.getB2DPoint(j);
- B2DPoint* pSmallest=0;
- for(B2DPoint* pCurr=aTmp.begin(); pCurr!=aTmp.end(); ++pCurr)
+ std::vector<B2DPoint>::iterator pSmallest=aTmp2.end();
+ for(std::vector<B2DPoint>::iterator pCurr=aTmp2.begin(); pCurr!=aTmp2.end(); ++pCurr)
{
- if( ! pSmallest || compare(*pCurr, *pSmallest) )
+ if( pSmallest == aTmp2.end() || compare(*pCurr, *pSmallest) )
{
pSmallest=pCurr;
}
}
- if( pSmallest )
- std::rotate(aTmp.begin(),pSmallest,aTmp.end());
+ if( pSmallest != aTmp2.end() )
+ std::rotate(aTmp2.begin(),pSmallest,aTmp2.end());
+
+ aTmp.clear();
+ for(std::vector<B2DPoint>::iterator pCurr=aTmp2.begin(); pCurr!=aTmp2.end(); ++pCurr)
+ aTmp.append(*pCurr);
aRes.append(aTmp);
}
More information about the Libreoffice-commits
mailing list