Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPP: Make functions mostly noexcept to improve runtime performance #14613

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
252 changes: 130 additions & 122 deletions deploy/cpp_infer/include/clipper.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,22 @@ struct IntPoint {
cInt Y;
#ifdef use_xyz
cInt Z;
IntPoint(cInt x = 0, cInt y = 0, cInt z = 0) : X(x), Y(y), Z(z){};
IntPoint(IntPoint const &ip) : X(ip.X), Y(ip.Y), Z(ip.Z) {}
IntPoint(cInt x = 0, cInt y = 0, cInt z = 0) noexcept : X(x), Y(y), Z(z) {}
IntPoint(IntPoint const &ip) noexcept : X(ip.X), Y(ip.Y), Z(ip.Z) {}
#else
IntPoint(cInt x = 0, cInt y = 0) : X(x), Y(y){};
IntPoint(IntPoint const &ip) : X(ip.X), Y(ip.Y) {}
IntPoint(cInt x = 0, cInt y = 0) noexcept : X(x), Y(y) {}
IntPoint(IntPoint const &ip) noexcept : X(ip.X), Y(ip.Y) {}
#endif

inline void reset(cInt x = 0, cInt y = 0) noexcept {
X = x;
Y = y;
}

friend inline bool operator==(const IntPoint &a, const IntPoint &b) {
friend inline bool operator==(const IntPoint &a, const IntPoint &b) noexcept {
return a.X == b.X && a.Y == b.Y;
}
friend inline bool operator!=(const IntPoint &a, const IntPoint &b) {
friend inline bool operator!=(const IntPoint &a, const IntPoint &b) noexcept {
return a.X != b.X || a.Y != b.Y;
}
};
Expand All @@ -109,18 +109,18 @@ struct IntPoint {
typedef std::vector<IntPoint> Path;
typedef std::vector<Path> Paths;

inline Path &operator<<(Path &poly, IntPoint &&p) {
inline Path &operator<<(Path &poly, IntPoint &&p) noexcept {
poly.emplace_back(std::forward<IntPoint>(p));
return poly;
}
inline Paths &operator<<(Paths &polys, Path &&p) {
inline Paths &operator<<(Paths &polys, Path &&p) noexcept {
polys.emplace_back(std::forward<Path>(p));
return polys;
}

std::ostream &operator<<(std::ostream &s, const IntPoint &p);
std::ostream &operator<<(std::ostream &s, const Path &p);
std::ostream &operator<<(std::ostream &s, const Paths &p);
std::ostream &operator<<(std::ostream &s, const IntPoint &p) noexcept;
std::ostream &operator<<(std::ostream &s, const Path &p) noexcept;
std::ostream &operator<<(std::ostream &s, const Paths &p) noexcept;

struct DoublePoint {
double X;
Expand Down Expand Up @@ -158,69 +158,75 @@ typedef std::vector<PolyNode *> PolyNodes;

class PolyNode {
public:
PolyNode();
virtual ~PolyNode(){};
PolyNode() noexcept;
virtual ~PolyNode() {}
Path Contour;
PolyNodes Childs;
PolyNode *Parent;
PolyNode *GetNext() const;
bool IsHole() const;
bool IsOpen() const;
int ChildCount() const;
PolyNode *GetNext() const noexcept;
bool IsHole() const noexcept;
bool IsOpen() const noexcept;
int ChildCount() const noexcept;

private:
// PolyNode& operator =(PolyNode& other);
unsigned Index; // node index in Parent.Childs
bool m_IsOpen;
JoinType m_jointype;
EndType m_endtype;
PolyNode *GetNextSiblingUp() const;
void AddChild(PolyNode &child);
PolyNode *GetNextSiblingUp() const noexcept;
void AddChild(PolyNode &child) noexcept;
friend class Clipper; // to access Index
friend class ClipperOffset;
};

class PolyTree : public PolyNode {
public:
~PolyTree() { Clear(); };
PolyNode *GetFirst() const;
void Clear();
int Total() const;
~PolyTree() { Clear(); }
PolyNode *GetFirst() const noexcept;
void Clear() noexcept;
int Total() const noexcept;

private:
// PolyTree& operator =(PolyTree& other);
PolyNodes AllNodes;
friend class Clipper; // to access AllNodes
};

bool Orientation(const Path &poly);
double Area(const Path &poly);
int PointInPolygon(const IntPoint &pt, const Path &path);
bool Orientation(const Path &poly) noexcept;
double Area(const Path &poly) noexcept;
int PointInPolygon(const IntPoint &pt, const Path &path) noexcept;

#if 0
void SimplifyPolygon(const Path &in_poly, Paths &out_polys,
PolyFillType fillType = pftEvenOdd);
void SimplifyPolygons(const Paths &in_polys, Paths &out_polys,
PolyFillType fillType = pftEvenOdd);
void SimplifyPolygons(Paths &polys, PolyFillType fillType = pftEvenOdd);
#endif

void CleanPolygon(const Path &in_poly, Path &out_poly, double distance = 1.415);
void CleanPolygon(Path &poly, double distance = 1.415);
void CleanPolygon(const Path &in_poly, Path &out_poly,
double distance = 1.415) noexcept;
void CleanPolygon(Path &poly, double distance = 1.415) noexcept;
void CleanPolygons(const Paths &in_polys, Paths &out_polys,
double distance = 1.415);
void CleanPolygons(Paths &polys, double distance = 1.415);
double distance = 1.415) noexcept;
void CleanPolygons(Paths &polys, double distance = 1.415) noexcept;

#if 0
void MinkowskiSum(const Path &pattern, const Path &path, Paths &solution,
bool pathIsClosed);
void MinkowskiSum(const Path &pattern, const Paths &paths, Paths &solution,
bool pathIsClosed);

void MinkowskiDiff(const Path &poly1, const Path &poly2, Paths &solution);
#endif

void PolyTreeToPaths(const PolyTree &polytree, Paths &paths);
void ClosedPathsFromPolyTree(const PolyTree &polytree, Paths &paths);
void OpenPathsFromPolyTree(PolyTree &polytree, Paths &paths);
void PolyTreeToPaths(const PolyTree &polytree, Paths &paths) noexcept;
void ClosedPathsFromPolyTree(const PolyTree &polytree, Paths &paths) noexcept;
void OpenPathsFromPolyTree(PolyTree &polytree, Paths &paths) noexcept;

void ReversePath(Path &p);
void ReversePaths(Paths &p);
void ReversePath(Path &p) noexcept;
void ReversePaths(Paths &p) noexcept;

struct IntRect {
cInt left;
Expand Down Expand Up @@ -252,29 +258,29 @@ typedef std::vector<IntersectNode *> IntersectList;
// polygon coordinates into edge objects that are stored in a LocalMinima list.
class ClipperBase {
public:
ClipperBase();
ClipperBase() noexcept;
virtual ~ClipperBase();
virtual bool AddPath(const Path &pg, PolyType PolyTyp, bool Closed);
bool AddPaths(const Paths &ppg, PolyType PolyTyp, bool Closed);
virtual void Clear();
IntRect GetBounds();
bool PreserveCollinear() { return m_PreserveCollinear; };
void PreserveCollinear(bool value) { m_PreserveCollinear = value; };
virtual void Clear() noexcept;
IntRect GetBounds() noexcept;
bool PreserveCollinear() const noexcept { return m_PreserveCollinear; }
void PreserveCollinear(bool value) noexcept { m_PreserveCollinear = value; }

protected:
void DisposeLocalMinimaList();
TEdge *AddBoundsToLML(TEdge *e, bool IsClosed);
virtual void Reset();
TEdge *ProcessBound(TEdge *E, bool IsClockwise);
void InsertScanbeam(const cInt Y);
bool PopScanbeam(cInt &Y);
bool LocalMinimaPending();
bool PopLocalMinima(cInt Y, const LocalMinimum *&locMin);
OutRec *CreateOutRec();
void DisposeAllOutRecs();
void DisposeOutRec(PolyOutList::size_type index);
void SwapPositionsInAEL(TEdge *edge1, TEdge *edge2);
void DeleteFromAEL(TEdge *e);
void DisposeLocalMinimaList() noexcept;
TEdge *AddBoundsToLML(TEdge *e, bool IsClosed) noexcept;
virtual void Reset() noexcept;
TEdge *ProcessBound(TEdge *E, bool IsClockwise) noexcept;
void InsertScanbeam(const cInt Y) noexcept;
bool PopScanbeam(cInt &Y) noexcept;
bool LocalMinimaPending() noexcept;
bool PopLocalMinima(cInt Y, const LocalMinimum *&locMin) noexcept;
OutRec *CreateOutRec() noexcept;
void DisposeAllOutRecs() noexcept;
void DisposeOutRec(PolyOutList::size_type index) noexcept;
void SwapPositionsInAEL(TEdge *edge1, TEdge *edge2) noexcept;
void DeleteFromAEL(TEdge *e) noexcept;
void UpdateEdgeIntoAEL(TEdge *&e);

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

class Clipper : public virtual ClipperBase {
public:
Clipper(int initOptions = 0);
Clipper(int initOptions = 0) noexcept;
bool Execute(ClipType clipType, Paths &solution,
PolyFillType fillType = pftEvenOdd);
bool Execute(ClipType clipType, Paths &solution, PolyFillType subjFillType,
PolyFillType clipFillType);
bool Execute(ClipType clipType, PolyTree &polytree,
PolyFillType fillType = pftEvenOdd);
PolyFillType fillType = pftEvenOdd) noexcept;
bool Execute(ClipType clipType, PolyTree &polytree, PolyFillType subjFillType,
PolyFillType clipFillType);
bool ReverseSolution() { return m_ReverseOutput; };
void ReverseSolution(bool value) { m_ReverseOutput = value; };
bool StrictlySimple() { return m_StrictSimple; };
void StrictlySimple(bool value) { m_StrictSimple = value; };
PolyFillType clipFillType) noexcept;
bool ReverseSolution() const noexcept { return m_ReverseOutput; }
void ReverseSolution(bool value) noexcept { m_ReverseOutput = value; }
bool StrictlySimple() const noexcept { return m_StrictSimple; }
void StrictlySimple(bool value) noexcept { m_StrictSimple = value; }
// set the callback function for z value filling on intersections (otherwise Z
// is 0)
#ifdef use_xyz
void ZFillFunction(ZFillCallback zFillFunc);
void ZFillFunction(ZFillCallback zFillFunc) noexcept;
#endif
protected:
virtual bool ExecuteInternal();
virtual bool ExecuteInternal() noexcept;

private:
JoinList m_Joins;
Expand All @@ -333,71 +339,73 @@ class Clipper : public virtual ClipperBase {
#ifdef use_xyz
ZFillCallback m_ZFill; // custom callback
#endif
void SetWindingCount(TEdge &edge);
bool IsEvenOddFillType(const TEdge &edge) const;
bool IsEvenOddAltFillType(const TEdge &edge) const;
void InsertLocalMinimaIntoAEL(const cInt botY);
void InsertEdgeIntoAEL(TEdge *edge, TEdge *startEdge);
void AddEdgeToSEL(TEdge *edge);
bool PopEdgeFromSEL(TEdge *&edge);
void CopyAELToSEL();
void DeleteFromSEL(TEdge *e);
void SwapPositionsInSEL(TEdge *edge1, TEdge *edge2);
bool IsContributing(const TEdge &edge) const;
bool IsTopHorz(const cInt XPos);
void SetWindingCount(TEdge &edge) noexcept;
bool IsEvenOddFillType(const TEdge &edge) const noexcept;
bool IsEvenOddAltFillType(const TEdge &edge) const noexcept;
void InsertLocalMinimaIntoAEL(const cInt botY) noexcept;
void InsertEdgeIntoAEL(TEdge *edge, TEdge *startEdge) noexcept;
void AddEdgeToSEL(TEdge *edge) noexcept;
bool PopEdgeFromSEL(TEdge *&edge) noexcept;
void CopyAELToSEL() noexcept;
void DeleteFromSEL(TEdge *e) noexcept;
void SwapPositionsInSEL(TEdge *edge1, TEdge *edge2) noexcept;
bool IsContributing(const TEdge &edge) const noexcept;
bool IsTopHorz(const cInt XPos) noexcept;
void DoMaxima(TEdge *e);
void ProcessHorizontals();
void ProcessHorizontal(TEdge *horzEdge);
void AddLocalMaxPoly(TEdge *e1, TEdge *e2, const IntPoint &pt);
OutPt *AddLocalMinPoly(TEdge *e1, TEdge *e2, const IntPoint &pt);
OutRec *GetOutRec(int idx);
void AppendPolygon(TEdge *e1, TEdge *e2);
void IntersectEdges(TEdge *e1, TEdge *e2, IntPoint &pt);
OutPt *AddOutPt(TEdge *e, const IntPoint &pt);
OutPt *GetLastOutPt(TEdge *e);
void ProcessHorizontals() noexcept;
void ProcessHorizontal(TEdge *horzEdge) noexcept;
void AddLocalMaxPoly(TEdge *e1, TEdge *e2, const IntPoint &pt) noexcept;
OutPt *AddLocalMinPoly(TEdge *e1, TEdge *e2, const IntPoint &pt) noexcept;
OutRec *GetOutRec(int idx) noexcept;
void AppendPolygon(TEdge *e1, TEdge *e2) noexcept;
void IntersectEdges(TEdge *e1, TEdge *e2, IntPoint &pt) noexcept;
OutPt *AddOutPt(TEdge *e, const IntPoint &pt) noexcept;
OutPt *GetLastOutPt(TEdge *e) noexcept;
bool ProcessIntersections(const cInt topY);
void BuildIntersectList(const cInt topY);
void ProcessIntersectList();
void BuildIntersectList(const cInt topY) noexcept;
void ProcessIntersectList() noexcept;
void ProcessEdgesAtTopOfScanbeam(const cInt topY);
void BuildResult(Paths &polys);
void BuildResult2(PolyTree &polytree);
void SetHoleState(TEdge *e, OutRec *outrec);
void DisposeIntersectNodes();
bool FixupIntersectionOrder();
void FixupOutPolygon(OutRec &outrec);
void FixupOutPolyline(OutRec &outrec);
bool IsHole(TEdge *e);
bool FindOwnerFromSplitRecs(OutRec &outRec, OutRec *&currOrfl);
void FixHoleLinkage(OutRec &outrec);
void AddJoin(OutPt *op1, OutPt *op2, const IntPoint offPt);
void ClearJoins();
void ClearGhostJoins();
void AddGhostJoin(OutPt *op, const IntPoint offPt);
bool JoinPoints(Join *j, OutRec *outRec1, OutRec *outRec2);
void JoinCommonEdges();
void DoSimplePolygons();
void FixupFirstLefts1(OutRec *OldOutRec, OutRec *NewOutRec);
void FixupFirstLefts2(OutRec *InnerOutRec, OutRec *OuterOutRec);
void FixupFirstLefts3(OutRec *OldOutRec, OutRec *NewOutRec);
void BuildResult(Paths &polys) noexcept;
void BuildResult2(PolyTree &polytree) noexcept;
void SetHoleState(TEdge *e, OutRec *outrec) noexcept;
void DisposeIntersectNodes() noexcept;
bool FixupIntersectionOrder() noexcept;
void FixupOutPolygon(OutRec &outrec) noexcept;
void FixupOutPolyline(OutRec &outrec) noexcept;
bool IsHole(TEdge *e) noexcept;
bool FindOwnerFromSplitRecs(OutRec &outRec, OutRec *&currOrfl) noexcept;
void FixHoleLinkage(OutRec &outrec) noexcept;
void AddJoin(OutPt *op1, OutPt *op2, const IntPoint offPt) noexcept;
void ClearJoins() noexcept;
void ClearGhostJoins() noexcept;
void AddGhostJoin(OutPt *op, const IntPoint offPt) noexcept;
bool JoinPoints(Join *j, OutRec *outRec1, OutRec *outRec2) noexcept;
void JoinCommonEdges() noexcept;
void DoSimplePolygons() noexcept;
void FixupFirstLefts1(OutRec *OldOutRec, OutRec *NewOutRec) noexcept;
void FixupFirstLefts2(OutRec *InnerOutRec, OutRec *OuterOutRec) noexcept;
void FixupFirstLefts3(OutRec *OldOutRec, OutRec *NewOutRec) noexcept;
#ifdef use_xyz
void SetZ(IntPoint &pt, TEdge &e1, TEdge &e2);
void SetZ(IntPoint &pt, TEdge &e1, TEdge &e2) noexcept;
#endif
};
//------------------------------------------------------------------------------

class ClipperOffset {
public:
ClipperOffset(double miterLimit = 2.0, double roundPrecision = 0.25);
ClipperOffset(double miterLimit = 2.0, double roundPrecision = 0.25) noexcept;
~ClipperOffset();
void AddPath(const Path &path, JoinType joinType, EndType endType);
void AddPaths(const Paths &paths, JoinType joinType, EndType endType);
void Execute(Paths &solution, double delta);
void Execute(PolyTree &solution, double delta);
void Clear();
void AddPath(const Path &path, JoinType joinType, EndType endType) noexcept;
void AddPaths(const Paths &paths, JoinType joinType,
EndType endType) noexcept;
bool Execute(Paths &solution, double delta) noexcept;
bool Execute(PolyTree &solution, double delta) noexcept;
void Clear() noexcept;

private:
double MiterLimit;
double ArcTolerance;

private:
Paths m_destPolys;
Path m_srcPoly;
Path m_destPoly;
Expand All @@ -407,20 +415,20 @@ class ClipperOffset {
IntPoint m_lowest;
PolyNode m_polyNodes;

void FixOrientations();
void DoOffset(double delta);
void OffsetPoint(int j, int &k, JoinType jointype);
void DoSquare(int j, int k);
void DoMiter(int j, int k, double r);
void DoRound(int j, int k);
void FixOrientations() noexcept;
void DoOffset(double delta) noexcept;
void OffsetPoint(int j, int &k, JoinType jointype) noexcept;
void DoSquare(int j, int k) noexcept;
void DoMiter(int j, int k, double r) noexcept;
void DoRound(int j, int k) noexcept;
};
//------------------------------------------------------------------------------

class clipperException : public std::exception {
public:
clipperException(const char *description) : m_descr(description) {}
virtual ~clipperException() throw() {}
virtual const char *what() const throw() { return m_descr.c_str(); }
clipperException(const char *description) noexcept : m_descr(description) {}
~clipperException() {}
virtual const char *what() const noexcept { return m_descr.c_str(); }

private:
std::string m_descr;
Expand Down
Loading