From 0f7f8f45e4a6957c67d937e2a66fa04fbc4a3f61 Mon Sep 17 00:00:00 2001 From: soyer Date: Thu, 2 Jan 2025 08:47:50 +0100 Subject: [PATCH] pass strings by const reference and use find_last_not_of (#779) * pass std::strings by const reference * use std::string::find_last_not_of --- src/minidexed.cpp | 6 +++--- src/minidexed.h | 4 ++-- src/performanceconfig.cpp | 12 ++---------- src/performanceconfig.h | 2 +- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/minidexed.cpp b/src/minidexed.cpp index 2e45f46..1a714fc 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -1968,9 +1968,9 @@ std::string CMiniDexed::GetNewPerformanceDefaultName(void) return m_PerformanceConfig.GetNewPerformanceDefaultName(); } -void CMiniDexed::SetNewPerformanceName(std::string nName) +void CMiniDexed::SetNewPerformanceName(const std::string &Name) { - m_PerformanceConfig.SetNewPerformanceName(nName); + m_PerformanceConfig.SetNewPerformanceName(Name); } bool CMiniDexed::IsValidPerformance(unsigned nID) @@ -1983,7 +1983,7 @@ bool CMiniDexed::IsValidPerformanceBank(unsigned nBankID) return m_PerformanceConfig.IsValidPerformanceBank(nBankID); } -void CMiniDexed::SetVoiceName (std::string VoiceName, unsigned nTG) +void CMiniDexed::SetVoiceName (const std::string &VoiceName, unsigned nTG) { assert (nTG < CConfig::AllToneGenerators); if (nTG >= m_nToneGenerators) return; // Not an active TG diff --git a/src/minidexed.h b/src/minidexed.h index 69dcf9c..bb6290b 100644 --- a/src/minidexed.h +++ b/src/minidexed.h @@ -164,8 +164,8 @@ public: int GetParameter (TParameter Parameter); std::string GetNewPerformanceDefaultName(void); - void SetNewPerformanceName(std::string nName); - void SetVoiceName (std::string VoiceName, unsigned nTG); + void SetNewPerformanceName(const std::string &Name); + void SetVoiceName (const std::string &VoiceName, unsigned nTG); bool DeletePerformance(unsigned nID); bool DoDeletePerformance(void); diff --git a/src/performanceconfig.cpp b/src/performanceconfig.cpp index 8a182e7..d0ce2de 100644 --- a/src/performanceconfig.cpp +++ b/src/performanceconfig.cpp @@ -1095,17 +1095,9 @@ std::string CPerformanceConfig::GetNewPerformanceDefaultName(void) return "Perf" + nIndex; } -void CPerformanceConfig::SetNewPerformanceName(std::string nName) +void CPerformanceConfig::SetNewPerformanceName(const std::string &Name) { - int i = nName.length(); - do - { - --i; - } - while (i>=0 && nName[i] == 32); - nName=nName.substr(0,i+1) ; - - NewPerformanceName = nName; + NewPerformanceName = Name.substr(0, Name.find_last_not_of(' ') + 1); } bool CPerformanceConfig::DeletePerformance(unsigned nID) diff --git a/src/performanceconfig.h b/src/performanceconfig.h index c9c4b27..916a2ee 100644 --- a/src/performanceconfig.h +++ b/src/performanceconfig.h @@ -137,7 +137,7 @@ public: bool CreateNewPerformanceFile(void); bool GetInternalFolderOk(); std::string GetNewPerformanceDefaultName(void); - void SetNewPerformanceName(std::string nName); + void SetNewPerformanceName(const std::string &Name); bool DeletePerformance(unsigned nID); bool CheckFreePerformanceSlot(void); std::string AddPerformanceBankDirName(unsigned nBankID);