From 4895a54c6e2f6793a9bce2b2b7f31c1a0c880fd4 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <github@naumov.de> Date: Sun, 18 Sep 2022 20:32:04 +0200 Subject: [PATCH] [CL] Avoid string copies. Use move --- ChemistryLib/PhreeqcKernelData/CreateKineticReactant.cpp | 2 +- ChemistryLib/PhreeqcKernelData/KineticReactant.cpp | 7 +++---- ChemistryLib/PhreeqcKernelData/KineticReactant.h | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ChemistryLib/PhreeqcKernelData/CreateKineticReactant.cpp b/ChemistryLib/PhreeqcKernelData/CreateKineticReactant.cpp index d3589afa565..43fb4710358 100644 --- a/ChemistryLib/PhreeqcKernelData/CreateKineticReactant.cpp +++ b/ChemistryLib/PhreeqcKernelData/CreateKineticReactant.cpp @@ -49,7 +49,7 @@ std::unique_ptr<Kinetics> createKineticReactants( 1); std::fill(std::begin(*amount), std::end(*amount), initial_amount); - kinetic_reactants.emplace_back(name, initial_amount); + kinetic_reactants.emplace_back(std::move(name), initial_amount); } return std::make_unique<Kinetics>(kinetic_reactants); diff --git a/ChemistryLib/PhreeqcKernelData/KineticReactant.cpp b/ChemistryLib/PhreeqcKernelData/KineticReactant.cpp index 04c801cd38f..688bd343e68 100644 --- a/ChemistryLib/PhreeqcKernelData/KineticReactant.cpp +++ b/ChemistryLib/PhreeqcKernelData/KineticReactant.cpp @@ -16,11 +16,10 @@ namespace ChemistryLib { namespace PhreeqcKernelData { -KineticReactant::KineticReactant(std::string const& name, - double const initial_amount) +KineticReactant::KineticReactant(std::string name, double const initial_amount) { - rate_name = name.c_str(); - namecoef.add(name.c_str(), 1.0); + rate_name = std::move(name); + namecoef.add(rate_name.c_str(), 1.0); m = initial_amount; m0 = initial_amount; } diff --git a/ChemistryLib/PhreeqcKernelData/KineticReactant.h b/ChemistryLib/PhreeqcKernelData/KineticReactant.h index b6a5d0f3192..c27275300af 100644 --- a/ChemistryLib/PhreeqcKernelData/KineticReactant.h +++ b/ChemistryLib/PhreeqcKernelData/KineticReactant.h @@ -22,7 +22,7 @@ namespace PhreeqcKernelData class KineticReactant final : private cxxKineticsComp { public: - KineticReactant(std::string const& name, double const initial_amount); + KineticReactant(std::string name, double const initial_amount); cxxKineticsComp const* castToBaseClass() const { -- GitLab