Skip to content

Commit ea71030

Browse files
authored
Make functions mostly noexcept to improve runtime performance (#14613)
1 parent c685537 commit ea71030

22 files changed

+575
-503
lines changed

deploy/cpp_infer/include/clipper.h

+130-122
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,22 @@ struct IntPoint {
8585
cInt Y;
8686
#ifdef use_xyz
8787
cInt Z;
88-
IntPoint(cInt x = 0, cInt y = 0, cInt z = 0) : X(x), Y(y), Z(z){};
89-
IntPoint(IntPoint const &ip) : X(ip.X), Y(ip.Y), Z(ip.Z) {}
88+
IntPoint(cInt x = 0, cInt y = 0, cInt z = 0) noexcept : X(x), Y(y), Z(z) {}
89+
IntPoint(IntPoint const &ip) noexcept : X(ip.X), Y(ip.Y), Z(ip.Z) {}
9090
#else
91-
IntPoint(cInt x = 0, cInt y = 0) : X(x), Y(y){};
92-
IntPoint(IntPoint const &ip) : X(ip.X), Y(ip.Y) {}
91+
IntPoint(cInt x = 0, cInt y = 0) noexcept : X(x), Y(y) {}
92+
IntPoint(IntPoint const &ip) noexcept : X(ip.X), Y(ip.Y) {}
9393
#endif
9494

9595
inline void reset(cInt x = 0, cInt y = 0) noexcept {
9696
X = x;
9797
Y = y;
9898
}
9999

100-
friend inline bool operator==(const IntPoint &a, const IntPoint &b) {
100+
friend inline bool operator==(const IntPoint &a, const IntPoint &b) noexcept {
101101
return a.X == b.X && a.Y == b.Y;
102102
}
103-
friend inline bool operator!=(const IntPoint &a, const IntPoint &b) {
103+
friend inline bool operator!=(const IntPoint &a, const IntPoint &b) noexcept {
104104
return a.X != b.X || a.Y != b.Y;
105105
}
106106
};
@@ -109,18 +109,18 @@ struct IntPoint {
109109
typedef std::vector<IntPoint> Path;
110110
typedef std::vector<Path> Paths;
111111

112-
inline Path &operator<<(Path &poly, IntPoint &&p) {
112+
inline Path &operator<<(Path &poly, IntPoint &&p) noexcept {
113113
poly.emplace_back(std::forward<IntPoint>(p));
114114
return poly;
115115
}
116-
inline Paths &operator<<(Paths &polys, Path &&p) {
116+
inline Paths &operator<<(Paths &polys, Path &&p) noexcept {
117117
polys.emplace_back(std::forward<Path>(p));
118118
return polys;
119119
}
120120

121-
std::ostream &operator<<(std::ostream &s, const IntPoint &p);
122-
std::ostream &operator<<(std::ostream &s, const Path &p);
123-
std::ostream &operator<<(std::ostream &s, const Paths &p);
121+
std::ostream &operator<<(std::ostream &s, const IntPoint &p) noexcept;
122+
std::ostream &operator<<(std::ostream &s, const Path &p) noexcept;
123+
std::ostream &operator<<(std::ostream &s, const Paths &p) noexcept;
124124

125125
struct DoublePoint {
126126
double X;
@@ -158,69 +158,75 @@ typedef std::vector<PolyNode *> PolyNodes;
158158

159159
class PolyNode {
160160
public:
161-
PolyNode();
162-
virtual ~PolyNode(){};
161+
PolyNode() noexcept;
162+
virtual ~PolyNode() {}
163163
Path Contour;
164164
PolyNodes Childs;
165165
PolyNode *Parent;
166-
PolyNode *GetNext() const;
167-
bool IsHole() const;
168-
bool IsOpen() const;
169-
int ChildCount() const;
166+
PolyNode *GetNext() const noexcept;
167+
bool IsHole() const noexcept;
168+
bool IsOpen() const noexcept;
169+
int ChildCount() const noexcept;
170170

171171
private:
172172
// PolyNode& operator =(PolyNode& other);
173173
unsigned Index; // node index in Parent.Childs
174174
bool m_IsOpen;
175175
JoinType m_jointype;
176176
EndType m_endtype;
177-
PolyNode *GetNextSiblingUp() const;
178-
void AddChild(PolyNode &child);
177+
PolyNode *GetNextSiblingUp() const noexcept;
178+
void AddChild(PolyNode &child) noexcept;
179179
friend class Clipper; // to access Index
180180
friend class ClipperOffset;
181181
};
182182

183183
class PolyTree : public PolyNode {
184184
public:
185-
~PolyTree() { Clear(); };
186-
PolyNode *GetFirst() const;
187-
void Clear();
188-
int Total() const;
185+
~PolyTree() { Clear(); }
186+
PolyNode *GetFirst() const noexcept;
187+
void Clear() noexcept;
188+
int Total() const noexcept;
189189

190190
private:
191191
// PolyTree& operator =(PolyTree& other);
192192
PolyNodes AllNodes;
193193
friend class Clipper; // to access AllNodes
194194
};
195195

196-
bool Orientation(const Path &poly);
197-
double Area(const Path &poly);
198-
int PointInPolygon(const IntPoint &pt, const Path &path);
196+
bool Orientation(const Path &poly) noexcept;
197+
double Area(const Path &poly) noexcept;
198+
int PointInPolygon(const IntPoint &pt, const Path &path) noexcept;
199199

200+
#if 0
200201
void SimplifyPolygon(const Path &in_poly, Paths &out_polys,
201202
PolyFillType fillType = pftEvenOdd);
202203
void SimplifyPolygons(const Paths &in_polys, Paths &out_polys,
203204
PolyFillType fillType = pftEvenOdd);
204205
void SimplifyPolygons(Paths &polys, PolyFillType fillType = pftEvenOdd);
206+
#endif
205207

206-
void CleanPolygon(const Path &in_poly, Path &out_poly, double distance = 1.415);
207-
void CleanPolygon(Path &poly, double distance = 1.415);
208+
void CleanPolygon(const Path &in_poly, Path &out_poly,
209+
double distance = 1.415) noexcept;
210+
void CleanPolygon(Path &poly, double distance = 1.415) noexcept;
208211
void CleanPolygons(const Paths &in_polys, Paths &out_polys,
209-
double distance = 1.415);
210-
void CleanPolygons(Paths &polys, double distance = 1.415);
212+
double distance = 1.415) noexcept;
213+
void CleanPolygons(Paths &polys, double distance = 1.415) noexcept;
211214

215+
#if 0
212216
void MinkowskiSum(const Path &pattern, const Path &path, Paths &solution,
213217
bool pathIsClosed);
214218
void MinkowskiSum(const Path &pattern, const Paths &paths, Paths &solution,
215219
bool pathIsClosed);
220+
216221
void MinkowskiDiff(const Path &poly1, const Path &poly2, Paths &solution);
222+
#endif
217223

218-
void PolyTreeToPaths(const PolyTree &polytree, Paths &paths);
219-
void ClosedPathsFromPolyTree(const PolyTree &polytree, Paths &paths);
220-
void OpenPathsFromPolyTree(PolyTree &polytree, Paths &paths);
224+
void PolyTreeToPaths(const PolyTree &polytree, Paths &paths) noexcept;
225+
void ClosedPathsFromPolyTree(const PolyTree &polytree, Paths &paths) noexcept;
226+
void OpenPathsFromPolyTree(PolyTree &polytree, Paths &paths) noexcept;
221227

222-
void ReversePath(Path &p);
223-
void ReversePaths(Paths &p);
228+
void ReversePath(Path &p) noexcept;
229+
void ReversePaths(Paths &p) noexcept;
224230

225231
struct IntRect {
226232
cInt left;
@@ -252,29 +258,29 @@ typedef std::vector<IntersectNode *> IntersectList;
252258
// polygon coordinates into edge objects that are stored in a LocalMinima list.
253259
class ClipperBase {
254260
public:
255-
ClipperBase();
261+
ClipperBase() noexcept;
256262
virtual ~ClipperBase();
257263
virtual bool AddPath(const Path &pg, PolyType PolyTyp, bool Closed);
258264
bool AddPaths(const Paths &ppg, PolyType PolyTyp, bool Closed);
259-
virtual void Clear();
260-
IntRect GetBounds();
261-
bool PreserveCollinear() { return m_PreserveCollinear; };
262-
void PreserveCollinear(bool value) { m_PreserveCollinear = value; };
265+
virtual void Clear() noexcept;
266+
IntRect GetBounds() noexcept;
267+
bool PreserveCollinear() const noexcept { return m_PreserveCollinear; }
268+
void PreserveCollinear(bool value) noexcept { m_PreserveCollinear = value; }
263269

264270
protected:
265-
void DisposeLocalMinimaList();
266-
TEdge *AddBoundsToLML(TEdge *e, bool IsClosed);
267-
virtual void Reset();
268-
TEdge *ProcessBound(TEdge *E, bool IsClockwise);
269-
void InsertScanbeam(const cInt Y);
270-
bool PopScanbeam(cInt &Y);
271-
bool LocalMinimaPending();
272-
bool PopLocalMinima(cInt Y, const LocalMinimum *&locMin);
273-
OutRec *CreateOutRec();
274-
void DisposeAllOutRecs();
275-
void DisposeOutRec(PolyOutList::size_type index);
276-
void SwapPositionsInAEL(TEdge *edge1, TEdge *edge2);
277-
void DeleteFromAEL(TEdge *e);
271+
void DisposeLocalMinimaList() noexcept;
272+
TEdge *AddBoundsToLML(TEdge *e, bool IsClosed) noexcept;
273+
virtual void Reset() noexcept;
274+
TEdge *ProcessBound(TEdge *E, bool IsClockwise) noexcept;
275+
void InsertScanbeam(const cInt Y) noexcept;
276+
bool PopScanbeam(cInt &Y) noexcept;
277+
bool LocalMinimaPending() noexcept;
278+
bool PopLocalMinima(cInt Y, const LocalMinimum *&locMin) noexcept;
279+
OutRec *CreateOutRec() noexcept;
280+
void DisposeAllOutRecs() noexcept;
281+
void DisposeOutRec(PolyOutList::size_type index) noexcept;
282+
void SwapPositionsInAEL(TEdge *edge1, TEdge *edge2) noexcept;
283+
void DeleteFromAEL(TEdge *e) noexcept;
278284
void UpdateEdgeIntoAEL(TEdge *&e);
279285

280286
typedef std::vector<LocalMinimum> MinimaList;
@@ -295,26 +301,26 @@ class ClipperBase {
295301

296302
class Clipper : public virtual ClipperBase {
297303
public:
298-
Clipper(int initOptions = 0);
304+
Clipper(int initOptions = 0) noexcept;
299305
bool Execute(ClipType clipType, Paths &solution,
300306
PolyFillType fillType = pftEvenOdd);
301307
bool Execute(ClipType clipType, Paths &solution, PolyFillType subjFillType,
302308
PolyFillType clipFillType);
303309
bool Execute(ClipType clipType, PolyTree &polytree,
304-
PolyFillType fillType = pftEvenOdd);
310+
PolyFillType fillType = pftEvenOdd) noexcept;
305311
bool Execute(ClipType clipType, PolyTree &polytree, PolyFillType subjFillType,
306-
PolyFillType clipFillType);
307-
bool ReverseSolution() { return m_ReverseOutput; };
308-
void ReverseSolution(bool value) { m_ReverseOutput = value; };
309-
bool StrictlySimple() { return m_StrictSimple; };
310-
void StrictlySimple(bool value) { m_StrictSimple = value; };
312+
PolyFillType clipFillType) noexcept;
313+
bool ReverseSolution() const noexcept { return m_ReverseOutput; }
314+
void ReverseSolution(bool value) noexcept { m_ReverseOutput = value; }
315+
bool StrictlySimple() const noexcept { return m_StrictSimple; }
316+
void StrictlySimple(bool value) noexcept { m_StrictSimple = value; }
311317
// set the callback function for z value filling on intersections (otherwise Z
312318
// is 0)
313319
#ifdef use_xyz
314-
void ZFillFunction(ZFillCallback zFillFunc);
320+
void ZFillFunction(ZFillCallback zFillFunc) noexcept;
315321
#endif
316322
protected:
317-
virtual bool ExecuteInternal();
323+
virtual bool ExecuteInternal() noexcept;
318324

319325
private:
320326
JoinList m_Joins;
@@ -333,71 +339,73 @@ class Clipper : public virtual ClipperBase {
333339
#ifdef use_xyz
334340
ZFillCallback m_ZFill; // custom callback
335341
#endif
336-
void SetWindingCount(TEdge &edge);
337-
bool IsEvenOddFillType(const TEdge &edge) const;
338-
bool IsEvenOddAltFillType(const TEdge &edge) const;
339-
void InsertLocalMinimaIntoAEL(const cInt botY);
340-
void InsertEdgeIntoAEL(TEdge *edge, TEdge *startEdge);
341-
void AddEdgeToSEL(TEdge *edge);
342-
bool PopEdgeFromSEL(TEdge *&edge);
343-
void CopyAELToSEL();
344-
void DeleteFromSEL(TEdge *e);
345-
void SwapPositionsInSEL(TEdge *edge1, TEdge *edge2);
346-
bool IsContributing(const TEdge &edge) const;
347-
bool IsTopHorz(const cInt XPos);
342+
void SetWindingCount(TEdge &edge) noexcept;
343+
bool IsEvenOddFillType(const TEdge &edge) const noexcept;
344+
bool IsEvenOddAltFillType(const TEdge &edge) const noexcept;
345+
void InsertLocalMinimaIntoAEL(const cInt botY) noexcept;
346+
void InsertEdgeIntoAEL(TEdge *edge, TEdge *startEdge) noexcept;
347+
void AddEdgeToSEL(TEdge *edge) noexcept;
348+
bool PopEdgeFromSEL(TEdge *&edge) noexcept;
349+
void CopyAELToSEL() noexcept;
350+
void DeleteFromSEL(TEdge *e) noexcept;
351+
void SwapPositionsInSEL(TEdge *edge1, TEdge *edge2) noexcept;
352+
bool IsContributing(const TEdge &edge) const noexcept;
353+
bool IsTopHorz(const cInt XPos) noexcept;
348354
void DoMaxima(TEdge *e);
349-
void ProcessHorizontals();
350-
void ProcessHorizontal(TEdge *horzEdge);
351-
void AddLocalMaxPoly(TEdge *e1, TEdge *e2, const IntPoint &pt);
352-
OutPt *AddLocalMinPoly(TEdge *e1, TEdge *e2, const IntPoint &pt);
353-
OutRec *GetOutRec(int idx);
354-
void AppendPolygon(TEdge *e1, TEdge *e2);
355-
void IntersectEdges(TEdge *e1, TEdge *e2, IntPoint &pt);
356-
OutPt *AddOutPt(TEdge *e, const IntPoint &pt);
357-
OutPt *GetLastOutPt(TEdge *e);
355+
void ProcessHorizontals() noexcept;
356+
void ProcessHorizontal(TEdge *horzEdge) noexcept;
357+
void AddLocalMaxPoly(TEdge *e1, TEdge *e2, const IntPoint &pt) noexcept;
358+
OutPt *AddLocalMinPoly(TEdge *e1, TEdge *e2, const IntPoint &pt) noexcept;
359+
OutRec *GetOutRec(int idx) noexcept;
360+
void AppendPolygon(TEdge *e1, TEdge *e2) noexcept;
361+
void IntersectEdges(TEdge *e1, TEdge *e2, IntPoint &pt) noexcept;
362+
OutPt *AddOutPt(TEdge *e, const IntPoint &pt) noexcept;
363+
OutPt *GetLastOutPt(TEdge *e) noexcept;
358364
bool ProcessIntersections(const cInt topY);
359-
void BuildIntersectList(const cInt topY);
360-
void ProcessIntersectList();
365+
void BuildIntersectList(const cInt topY) noexcept;
366+
void ProcessIntersectList() noexcept;
361367
void ProcessEdgesAtTopOfScanbeam(const cInt topY);
362-
void BuildResult(Paths &polys);
363-
void BuildResult2(PolyTree &polytree);
364-
void SetHoleState(TEdge *e, OutRec *outrec);
365-
void DisposeIntersectNodes();
366-
bool FixupIntersectionOrder();
367-
void FixupOutPolygon(OutRec &outrec);
368-
void FixupOutPolyline(OutRec &outrec);
369-
bool IsHole(TEdge *e);
370-
bool FindOwnerFromSplitRecs(OutRec &outRec, OutRec *&currOrfl);
371-
void FixHoleLinkage(OutRec &outrec);
372-
void AddJoin(OutPt *op1, OutPt *op2, const IntPoint offPt);
373-
void ClearJoins();
374-
void ClearGhostJoins();
375-
void AddGhostJoin(OutPt *op, const IntPoint offPt);
376-
bool JoinPoints(Join *j, OutRec *outRec1, OutRec *outRec2);
377-
void JoinCommonEdges();
378-
void DoSimplePolygons();
379-
void FixupFirstLefts1(OutRec *OldOutRec, OutRec *NewOutRec);
380-
void FixupFirstLefts2(OutRec *InnerOutRec, OutRec *OuterOutRec);
381-
void FixupFirstLefts3(OutRec *OldOutRec, OutRec *NewOutRec);
368+
void BuildResult(Paths &polys) noexcept;
369+
void BuildResult2(PolyTree &polytree) noexcept;
370+
void SetHoleState(TEdge *e, OutRec *outrec) noexcept;
371+
void DisposeIntersectNodes() noexcept;
372+
bool FixupIntersectionOrder() noexcept;
373+
void FixupOutPolygon(OutRec &outrec) noexcept;
374+
void FixupOutPolyline(OutRec &outrec) noexcept;
375+
bool IsHole(TEdge *e) noexcept;
376+
bool FindOwnerFromSplitRecs(OutRec &outRec, OutRec *&currOrfl) noexcept;
377+
void FixHoleLinkage(OutRec &outrec) noexcept;
378+
void AddJoin(OutPt *op1, OutPt *op2, const IntPoint offPt) noexcept;
379+
void ClearJoins() noexcept;
380+
void ClearGhostJoins() noexcept;
381+
void AddGhostJoin(OutPt *op, const IntPoint offPt) noexcept;
382+
bool JoinPoints(Join *j, OutRec *outRec1, OutRec *outRec2) noexcept;
383+
void JoinCommonEdges() noexcept;
384+
void DoSimplePolygons() noexcept;
385+
void FixupFirstLefts1(OutRec *OldOutRec, OutRec *NewOutRec) noexcept;
386+
void FixupFirstLefts2(OutRec *InnerOutRec, OutRec *OuterOutRec) noexcept;
387+
void FixupFirstLefts3(OutRec *OldOutRec, OutRec *NewOutRec) noexcept;
382388
#ifdef use_xyz
383-
void SetZ(IntPoint &pt, TEdge &e1, TEdge &e2);
389+
void SetZ(IntPoint &pt, TEdge &e1, TEdge &e2) noexcept;
384390
#endif
385391
};
386392
//------------------------------------------------------------------------------
387393

388394
class ClipperOffset {
389395
public:
390-
ClipperOffset(double miterLimit = 2.0, double roundPrecision = 0.25);
396+
ClipperOffset(double miterLimit = 2.0, double roundPrecision = 0.25) noexcept;
391397
~ClipperOffset();
392-
void AddPath(const Path &path, JoinType joinType, EndType endType);
393-
void AddPaths(const Paths &paths, JoinType joinType, EndType endType);
394-
void Execute(Paths &solution, double delta);
395-
void Execute(PolyTree &solution, double delta);
396-
void Clear();
398+
void AddPath(const Path &path, JoinType joinType, EndType endType) noexcept;
399+
void AddPaths(const Paths &paths, JoinType joinType,
400+
EndType endType) noexcept;
401+
bool Execute(Paths &solution, double delta) noexcept;
402+
bool Execute(PolyTree &solution, double delta) noexcept;
403+
void Clear() noexcept;
404+
405+
private:
397406
double MiterLimit;
398407
double ArcTolerance;
399408

400-
private:
401409
Paths m_destPolys;
402410
Path m_srcPoly;
403411
Path m_destPoly;
@@ -407,20 +415,20 @@ class ClipperOffset {
407415
IntPoint m_lowest;
408416
PolyNode m_polyNodes;
409417

410-
void FixOrientations();
411-
void DoOffset(double delta);
412-
void OffsetPoint(int j, int &k, JoinType jointype);
413-
void DoSquare(int j, int k);
414-
void DoMiter(int j, int k, double r);
415-
void DoRound(int j, int k);
418+
void FixOrientations() noexcept;
419+
void DoOffset(double delta) noexcept;
420+
void OffsetPoint(int j, int &k, JoinType jointype) noexcept;
421+
void DoSquare(int j, int k) noexcept;
422+
void DoMiter(int j, int k, double r) noexcept;
423+
void DoRound(int j, int k) noexcept;
416424
};
417425
//------------------------------------------------------------------------------
418426

419427
class clipperException : public std::exception {
420428
public:
421-
clipperException(const char *description) : m_descr(description) {}
422-
virtual ~clipperException() throw() {}
423-
virtual const char *what() const throw() { return m_descr.c_str(); }
429+
clipperException(const char *description) noexcept : m_descr(description) {}
430+
~clipperException() {}
431+
virtual const char *what() const noexcept { return m_descr.c_str(); }
424432

425433
private:
426434
std::string m_descr;

0 commit comments

Comments
 (0)