From 25ecfd8182a3eeab77e2f10d4765c4b46cf72259 Mon Sep 17 00:00:00 2001 From: RiccardoFrenner <76073356+RiccardoFrenner@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:06:07 +0200 Subject: [PATCH] Rewrite ParticleForce operator+ to improve performance. --- src/core/Particle.hpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/Particle.hpp b/src/core/Particle.hpp index 8e81bfe200..2e125ae3ab 100644 --- a/src/core/Particle.hpp +++ b/src/core/Particle.hpp @@ -299,15 +299,17 @@ struct ParticleForce { friend ParticleForce operator+(ParticleForce const &lhs, ParticleForce const &rhs) { -#ifdef ROTATION - return {lhs.f + rhs.f, lhs.torque + rhs.torque}; -#else - return lhs.f + rhs.f; -#endif + ParticleForce result = lhs; + result += rhs; + return result; } ParticleForce &operator+=(ParticleForce const &rhs) { - return *this = *this + rhs; + f += rhs.f; +#ifdef ROTATION + torque += rhs.torque; +#endif + return *this; } /** force. */