From 09ed6f125bcdc23bc016a4cf0a75b4ba11ed9048 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 15 Nov 2023 12:44:14 +0100 Subject: [PATCH] fix performance-* * performance-type-promotion-in-math-fn * performance-trivially-destructible * performance-noexcept-move-constructor * performance-faster-string-find --- src/Base/BoundBoxPyImp.cpp | 3 ++- src/Base/Builder3D.cpp | 4 ++-- src/Base/CoordinateSystem.cpp | 2 -- src/Base/CoordinateSystem.h | 2 +- src/Base/Rotation.h | 2 +- src/Base/Tools2D.h | 6 +++--- src/Base/Tools3D.h | 8 ++++---- src/Base/Vector3D.cpp | 18 ++++++++++-------- src/Base/Vector3D.h | 4 ++-- 9 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/Base/BoundBoxPyImp.cpp b/src/Base/BoundBoxPyImp.cpp index 72f3643c80..a3fecb25ef 100644 --- a/src/Base/BoundBoxPyImp.cpp +++ b/src/Base/BoundBoxPyImp.cpp @@ -65,7 +65,8 @@ int BoundBoxPy::PyInit(PyObject* args, PyObject* /*kwd*/) double xMax = 0.0; double yMax = 0.0; double zMax = 0.0; - PyObject *object1 {}, *object2 {}; + PyObject* object1 {}; + PyObject* object2 {}; BoundBoxPy::PointerType ptr = getBoundBoxPtr(); if (PyArg_ParseTuple(args, "d|ddddd", &xMin, &yMin, &zMin, &xMax, &yMax, &zMax)) { ptr->MaxX = xMax; diff --git a/src/Base/Builder3D.cpp b/src/Base/Builder3D.cpp index c46dae7691..d840ecc7c2 100644 --- a/src/Base/Builder3D.cpp +++ b/src/Base/Builder3D.cpp @@ -1073,7 +1073,7 @@ std::vector InventorLoader::readData(const char* fieldName) const bool found = false; while (std::getline(inp, str)) { std::string::size_type point = str.find(fieldName); - std::string::size_type open = str.find("["); + std::string::size_type open = str.find('['); if (point != std::string::npos && open > point) { str = str.substr(open); found = true; @@ -1101,7 +1101,7 @@ std::vector InventorLoader::readData(const char* fieldName) const } // search for ']' to finish the reading - if (str.find("]") != std::string::npos) { + if (str.find(']') != std::string::npos) { break; } } while (std::getline(inp, str)); diff --git a/src/Base/CoordinateSystem.cpp b/src/Base/CoordinateSystem.cpp index 8602a1e1e5..4134bed8f9 100644 --- a/src/Base/CoordinateSystem.cpp +++ b/src/Base/CoordinateSystem.cpp @@ -36,8 +36,6 @@ CoordinateSystem::CoordinateSystem() , ydir(0, 1, 0) {} -CoordinateSystem::~CoordinateSystem() = default; - void CoordinateSystem::setAxes(const Axis& vec, const Vector3d& xd) { if (xd.Sqr() < Base::Vector3d::epsilon()) { diff --git a/src/Base/CoordinateSystem.h b/src/Base/CoordinateSystem.h index ac4200c320..f38bb016be 100644 --- a/src/Base/CoordinateSystem.h +++ b/src/Base/CoordinateSystem.h @@ -41,7 +41,7 @@ public: CoordinateSystem(); CoordinateSystem(const CoordinateSystem&) = default; CoordinateSystem(CoordinateSystem&&) = default; - ~CoordinateSystem(); + ~CoordinateSystem() = default; CoordinateSystem& operator=(const CoordinateSystem&) = default; CoordinateSystem& operator=(CoordinateSystem&&) = default; diff --git a/src/Base/Rotation.h b/src/Base/Rotation.h index 35e4f281ef..7542c055d6 100644 --- a/src/Base/Rotation.h +++ b/src/Base/Rotation.h @@ -154,7 +154,7 @@ public: //@} /** Specialty constructors */ - static Rotation slerp(const Rotation& q1, const Rotation& q2, double t); + static Rotation slerp(const Rotation& q0, const Rotation& q1, double t); static Rotation identity(); /** diff --git a/src/Base/Tools2D.h b/src/Base/Tools2D.h index c878cff751..61b4abbf22 100644 --- a/src/Base/Tools2D.h +++ b/src/Base/Tools2D.h @@ -118,7 +118,7 @@ public: // operators inline BoundBox2d& operator=(const BoundBox2d&) = default; inline BoundBox2d& operator=(BoundBox2d&&) = default; - inline bool operator==(const BoundBox2d& rclBB) const; + inline bool operator==(const BoundBox2d& bbox) const; // methods inline double Width() const; @@ -182,7 +182,7 @@ public: ~Polygon2d() = default; inline Polygon2d& operator=(const Polygon2d& rclP); - inline Polygon2d& operator=(Polygon2d&& rclP); + inline Polygon2d& operator=(Polygon2d&& rclP) noexcept; // admin-interface inline size_t GetCtVectors() const; @@ -382,7 +382,7 @@ inline bool Vector2d::IsEqual(const Vector2d& v, double tolerance) const inline Polygon2d& Polygon2d::operator=(const Polygon2d& rclP) = default; -inline Polygon2d& Polygon2d::operator=(Polygon2d&& rclP) = default; +inline Polygon2d& Polygon2d::operator=(Polygon2d&& rclP) noexcept = default; inline void Polygon2d::DeleteAll() { diff --git a/src/Base/Tools3D.h b/src/Base/Tools3D.h index 5b8bd7f6c5..f8dfbe39c4 100644 --- a/src/Base/Tools3D.h +++ b/src/Base/Tools3D.h @@ -60,12 +60,12 @@ public: Line3() = default; ~Line3() = default; Line3(const Line3& line) = default; - Line3(Line3&& line) = default; + Line3(Line3&& line) noexcept = default; Line3(const Vector3& p1, const Vector3& p2); // operators Line3& operator=(const Line3& line) = default; - Line3& operator=(Line3&& line) = default; + Line3& operator=(Line3&& line) noexcept = default; bool operator==(const Line3& line) const; // methods @@ -112,10 +112,10 @@ public: Polygon3() = default; ~Polygon3() = default; Polygon3(const Polygon3& poly) = default; - Polygon3(Polygon3&& poly) = default; + Polygon3(Polygon3&& poly) noexcept = default; Polygon3& operator=(const Polygon3& poly) = default; - Polygon3& operator=(Polygon3&& poly) = default; + Polygon3& operator=(Polygon3&& poly) noexcept = default; size_t GetSize() const; void Add(const Vector3& pnt); diff --git a/src/Base/Vector3D.cpp b/src/Base/Vector3D.cpp index d59ee0b7bf..16574df72c 100644 --- a/src/Base/Vector3D.cpp +++ b/src/Base/Vector3D.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" +#include #include #include "Vector3D.h" @@ -215,9 +216,9 @@ bool Vector3<_Precision>::operator!=(const Vector3<_Precision>& rcVct) const template bool Vector3<_Precision>::operator==(const Vector3<_Precision>& rcVct) const { - return (fabs(x - rcVct.x) <= traits_type::epsilon()) - && (fabs(y - rcVct.y) <= traits_type::epsilon()) - && (fabs(z - rcVct.z) <= traits_type::epsilon()); + return (std::fabs(x - rcVct.x) <= traits_type::epsilon()) + && (std::fabs(y - rcVct.y) <= traits_type::epsilon()) + && (std::fabs(z - rcVct.z) <= traits_type::epsilon()); } template @@ -254,15 +255,16 @@ _Precision Vector3<_Precision>::DistanceToPlane(const Vector3<_Precision>& rclBa template _Precision Vector3<_Precision>::Length() const { - return static_cast<_Precision>(sqrt((x * x) + (y * y) + (z * z))); + return static_cast<_Precision>(std::sqrt((x * x) + (y * y) + (z * z))); } template -_Precision Vector3<_Precision>::DistanceToLine(const Vector3<_Precision>& rclBase, - const Vector3<_Precision>& rclDirect) const +_Precision Vector3<_Precision>::DistanceToLine(const Vector3<_Precision>& base, + const Vector3<_Precision>& dir) const { - return static_cast<_Precision>( - fabs((rclDirect % Vector3(*this - rclBase)).Length() / rclDirect.Length())); + // clang-format off + return static_cast<_Precision>(std::fabs((dir % Vector3(*this - base)).Length() / dir.Length())); + // clang-format on } template diff --git a/src/Base/Vector3D.h b/src/Base/Vector3D.h index a2bd4a6a10..c58817bf7c 100644 --- a/src/Base/Vector3D.h +++ b/src/Base/Vector3D.h @@ -118,7 +118,7 @@ public: /// Construction explicit Vector3(_Precision fx = 0.0, _Precision fy = 0.0, _Precision fz = 0.0); Vector3(const Vector3<_Precision>& v) = default; - Vector3(Vector3<_Precision>&& v) = default; + Vector3(Vector3<_Precision>&& v) noexcept = default; ~Vector3() = default; /** @name Operator */ @@ -145,7 +145,7 @@ public: Vector3& operator/=(_Precision fDiv); /// Assignment Vector3& operator=(const Vector3<_Precision>& v) = default; - Vector3& operator=(Vector3<_Precision>&& v) = default; + Vector3& operator=(Vector3<_Precision>&& v) noexcept = default; /// Scalar product _Precision operator*(const Vector3<_Precision>& rcVct) const; /// Scalar product