1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-06 15:37:44 +02:00

Sweep unnecessary wxString copies: commands

This commit is contained in:
Paul Licameli 2016-02-22 21:17:41 -05:00
parent 99f161c36c
commit 923a6ce4af
11 changed files with 60 additions and 56 deletions

View File

@ -39,12 +39,12 @@ void DecoratedCommand::Progress(double completed)
mCommand->Progress(completed); mCommand->Progress(completed);
} }
void DecoratedCommand::Status(wxString message) void DecoratedCommand::Status(const wxString &message)
{ {
mCommand->Status(message); mCommand->Status(message);
} }
void DecoratedCommand::Error(wxString message) void DecoratedCommand::Error(const wxString &message)
{ {
mCommand->Error(message); mCommand->Error(message);
} }
@ -162,12 +162,12 @@ void CommandImplementation::Progress(double completed)
mOutput->Progress(completed); mOutput->Progress(completed);
} }
void CommandImplementation::Status(wxString status) void CommandImplementation::Status(const wxString &status)
{ {
mOutput->Status(status); mOutput->Status(status);
} }
void CommandImplementation::Error(wxString message) void CommandImplementation::Error(const wxString &message)
{ {
mOutput->Error(message); mOutput->Error(message);
} }

View File

@ -61,8 +61,8 @@ class Command
{ {
public: public:
virtual void Progress(double completed) = 0; virtual void Progress(double completed) = 0;
virtual void Status(wxString message) = 0; virtual void Status(const wxString &message) = 0;
virtual void Error(wxString message) = 0; virtual void Error(const wxString &message) = 0;
virtual ~Command() { } virtual ~Command() { }
virtual wxString GetName() = 0; virtual wxString GetName() = 0;
virtual CommandSignature &GetSignature() = 0; virtual CommandSignature &GetSignature() = 0;
@ -77,8 +77,8 @@ protected:
Command *mCommand; Command *mCommand;
public: public:
virtual void Progress(double completed); virtual void Progress(double completed);
virtual void Status(wxString message); virtual void Status(const wxString &message) override;
virtual void Error(wxString message); virtual void Error(const wxString &message) override;
DecoratedCommand(Command *cmd) DecoratedCommand(Command *cmd)
: mCommand(cmd) : mCommand(cmd)
@ -130,8 +130,8 @@ protected:
public: public:
// Convenience methods for passing messages to the output target // Convenience methods for passing messages to the output target
void Progress(double completed); void Progress(double completed);
void Status(wxString status); void Status(const wxString &status) override;
void Error(wxString message); void Error(const wxString &message) override;
/// Constructor should not be called directly; only by a factory which /// Constructor should not be called directly; only by a factory which
/// ensures name and params are set appropriately for the command. /// ensures name and params are set appropriately for the command.

View File

@ -87,7 +87,7 @@ void CommandBuilder::Success(Command *cmd)
} }
void CommandBuilder::BuildCommand(const wxString &cmdName, void CommandBuilder::BuildCommand(const wxString &cmdName,
wxString cmdParams) const wxString &cmdParamsArg)
{ {
// Stage 1: create a Command object of the right type // Stage 1: create a Command object of the right type
@ -106,7 +106,7 @@ void CommandBuilder::BuildCommand(const wxString &cmdName,
wxASSERT(type != NULL); wxASSERT(type != NULL);
mCommand = type->Create(output); mCommand = type->Create(output);
mCommand->SetParameter(wxT("CommandName"), cmdName); mCommand->SetParameter(wxT("CommandName"), cmdName);
mCommand->SetParameter(wxT("ParamString"), cmdParams); mCommand->SetParameter(wxT("ParamString"), cmdParamsArg);
Success(new ApplyAndSendResponse(mCommand)); Success(new ApplyAndSendResponse(mCommand));
return; return;
} }
@ -117,7 +117,7 @@ void CommandBuilder::BuildCommand(const wxString &cmdName,
// Stage 2: set the parameters // Stage 2: set the parameters
ShuttleCli shuttle; ShuttleCli shuttle;
shuttle.mParams = cmdParams; shuttle.mParams = cmdParamsArg;
shuttle.mbStoreInClient = true; shuttle.mbStoreInClient = true;
ParamValueMap::const_iterator iter; ParamValueMap::const_iterator iter;
@ -138,6 +138,8 @@ void CommandBuilder::BuildCommand(const wxString &cmdName,
// Check for unrecognised parameters // Check for unrecognised parameters
wxString cmdParams(cmdParamsArg);
while (cmdParams != wxEmptyString) while (cmdParams != wxEmptyString)
{ {
cmdParams.Trim(true); cmdParams.Trim(true);
@ -166,8 +168,10 @@ void CommandBuilder::BuildCommand(const wxString &cmdName,
Success(new ApplyAndSendResponse(mCommand)); Success(new ApplyAndSendResponse(mCommand));
} }
void CommandBuilder::BuildCommand(wxString cmdString) void CommandBuilder::BuildCommand(const wxString &cmdStringArg)
{ {
wxString cmdString(cmdStringArg);
// Find the command name terminator... If there is more than one word and // Find the command name terminator... If there is more than one word and
// no terminator, the command is badly formed // no terminator, the command is badly formed
cmdString.Trim(true); cmdString.Trim(false); cmdString.Trim(true); cmdString.Trim(false);

View File

@ -31,8 +31,8 @@ class CommandBuilder
void Failure(const wxString &msg = wxEmptyString); void Failure(const wxString &msg = wxEmptyString);
void Success(Command *cmd); void Success(Command *cmd);
void BuildCommand(const wxString &cmdName, wxString cmdParams); void BuildCommand(const wxString &cmdName, const wxString &cmdParams);
void BuildCommand(wxString cmdString); void BuildCommand(const wxString &cmdString);
public: public:
CommandBuilder(const wxString &cmdString); CommandBuilder(const wxString &cmdString);
CommandBuilder(const wxString &cmdName, CommandBuilder(const wxString &cmdName,

View File

@ -957,7 +957,7 @@ void CommandManager::Enable(CommandListEntry *entry, bool enabled)
} }
} }
void CommandManager::Enable(wxString name, bool enabled) void CommandManager::Enable(const wxString &name, bool enabled)
{ {
CommandListEntry *entry = mCommandNameHash[name]; CommandListEntry *entry = mCommandNameHash[name];
if (!entry || !entry->menu) { if (!entry || !entry->menu) {
@ -997,7 +997,7 @@ bool CommandManager::GetEnabled(const wxString &name)
return entry->enabled; return entry->enabled;
} }
void CommandManager::Check(wxString name, bool checked) void CommandManager::Check(const wxString &name, bool checked)
{ {
CommandListEntry *entry = mCommandNameHash[name]; CommandListEntry *entry = mCommandNameHash[name];
if (!entry || !entry->menu) { if (!entry || !entry->menu) {
@ -1008,7 +1008,7 @@ void CommandManager::Check(wxString name, bool checked)
} }
///Changes the label text of a menu item ///Changes the label text of a menu item
void CommandManager::Modify(wxString name, wxString newLabel) void CommandManager::Modify(const wxString &name, const wxString &newLabel)
{ {
CommandListEntry *entry = mCommandNameHash[name]; CommandListEntry *entry = mCommandNameHash[name];
if (entry && entry->menu) { if (entry && entry->menu) {
@ -1017,7 +1017,7 @@ void CommandManager::Modify(wxString name, wxString newLabel)
} }
} }
void CommandManager::SetKeyFromName(wxString name, wxString key) void CommandManager::SetKeyFromName(const wxString &name, const wxString &key)
{ {
CommandListEntry *entry = mCommandNameHash[name]; CommandListEntry *entry = mCommandNameHash[name];
if (entry) { if (entry) {
@ -1025,7 +1025,7 @@ void CommandManager::SetKeyFromName(wxString name, wxString key)
} }
} }
void CommandManager::SetKeyFromIndex(int i, wxString key) void CommandManager::SetKeyFromIndex(int i, const wxString &key)
{ {
const auto &entry = mCommandList[i]; const auto &entry = mCommandList[i];
entry->key = KeyStringNormalize(key); entry->key = KeyStringNormalize(key);
@ -1284,7 +1284,7 @@ void CommandManager::GetAllCommandData(
} }
} }
} }
wxString CommandManager::GetLabelFromName(wxString name) wxString CommandManager::GetLabelFromName(const wxString &name)
{ {
CommandListEntry *entry = mCommandNameHash[name]; CommandListEntry *entry = mCommandNameHash[name];
if (!entry) if (!entry)
@ -1293,7 +1293,7 @@ wxString CommandManager::GetLabelFromName(wxString name)
return entry->label; return entry->label;
} }
wxString CommandManager::GetPrefixedLabelFromName(wxString name) wxString CommandManager::GetPrefixedLabelFromName(const wxString &name)
{ {
CommandListEntry *entry = mCommandNameHash[name]; CommandListEntry *entry = mCommandNameHash[name];
if (!entry) if (!entry)
@ -1310,7 +1310,7 @@ wxString CommandManager::GetPrefixedLabelFromName(wxString name)
#endif #endif
} }
wxString CommandManager::GetCategoryFromName(wxString name) wxString CommandManager::GetCategoryFromName(const wxString &name)
{ {
CommandListEntry *entry = mCommandNameHash[name]; CommandListEntry *entry = mCommandNameHash[name];
if (!entry) if (!entry)
@ -1319,7 +1319,7 @@ wxString CommandManager::GetCategoryFromName(wxString name)
return entry->labelTop; return entry->labelTop;
} }
wxString CommandManager::GetKeyFromName(wxString name) wxString CommandManager::GetKeyFromName(const wxString &name)
{ {
CommandListEntry *entry = mCommandNameHash[name]; CommandListEntry *entry = mCommandNameHash[name];
if (!entry) if (!entry)
@ -1328,7 +1328,7 @@ wxString CommandManager::GetKeyFromName(wxString name)
return entry->key; return entry->key;
} }
wxString CommandManager::GetDefaultKeyFromName(wxString name) wxString CommandManager::GetDefaultKeyFromName(const wxString &name)
{ {
CommandListEntry *entry = mCommandNameHash[name]; CommandListEntry *entry = mCommandNameHash[name];
if (!entry) if (!entry)
@ -1411,7 +1411,7 @@ void CommandManager::SetDefaultFlags(wxUint32 flags, wxUint32 mask)
mDefaultMask = mask; mDefaultMask = mask;
} }
void CommandManager::SetCommandFlags(wxString name, void CommandManager::SetCommandFlags(const wxString &name,
wxUint32 flags, wxUint32 mask) wxUint32 flags, wxUint32 mask)
{ {
CommandListEntry *entry = mCommandNameHash[name]; CommandListEntry *entry = mCommandNameHash[name];

View File

@ -184,7 +184,7 @@ class AUDACITY_DLL_API CommandManager: public XMLTagHandler
// For NEW items/commands // For NEW items/commands
void SetDefaultFlags(wxUint32 flags, wxUint32 mask); void SetDefaultFlags(wxUint32 flags, wxUint32 mask);
void SetCommandFlags(wxString name, wxUint32 flags, wxUint32 mask); void SetCommandFlags(const wxString &name, wxUint32 flags, wxUint32 mask);
void SetCommandFlags(const wxChar **names, void SetCommandFlags(const wxChar **names,
wxUint32 flags, wxUint32 mask); wxUint32 flags, wxUint32 mask);
// Pass multiple command names as const wxChar *, terminated by NULL // Pass multiple command names as const wxChar *, terminated by NULL
@ -195,16 +195,16 @@ class AUDACITY_DLL_API CommandManager: public XMLTagHandler
// //
void EnableUsingFlags(wxUint32 flags, wxUint32 mask); void EnableUsingFlags(wxUint32 flags, wxUint32 mask);
void Enable(wxString name, bool enabled); void Enable(const wxString &name, bool enabled);
void Check(wxString name, bool checked); void Check(const wxString &name, bool checked);
void Modify(wxString name, wxString newLabel); void Modify(const wxString &name, const wxString &newLabel);
// //
// Modifying accelerators // Modifying accelerators
// //
void SetKeyFromName(wxString name, wxString key); void SetKeyFromName(const wxString &name, const wxString &key);
void SetKeyFromIndex(int i, wxString key); void SetKeyFromIndex(int i, const wxString &key);
// //
// Executing commands // Executing commands
@ -231,11 +231,11 @@ class AUDACITY_DLL_API CommandManager: public XMLTagHandler
#endif #endif
bool includeMultis); bool includeMultis);
wxString GetLabelFromName(wxString name); wxString GetLabelFromName(const wxString &name);
wxString GetPrefixedLabelFromName(wxString name); wxString GetPrefixedLabelFromName(const wxString &name);
wxString GetCategoryFromName(wxString name); wxString GetCategoryFromName(const wxString &name);
wxString GetKeyFromName(wxString name); wxString GetKeyFromName(const wxString &name);
wxString GetDefaultKeyFromName(wxString name); wxString GetDefaultKeyFromName(const wxString &name);
bool GetEnabled(const wxString &name); bool GetEnabled(const wxString &name);

View File

@ -66,7 +66,7 @@ class CommandMessageTarget
{ {
public: public:
virtual ~CommandMessageTarget() {} virtual ~CommandMessageTarget() {}
virtual void Update(wxString message) = 0; virtual void Update(const wxString &message) = 0;
}; };
/// ///
@ -93,7 +93,7 @@ class NullMessageTarget : public CommandMessageTarget
{ {
public: public:
virtual ~NullMessageTarget() {} virtual ~NullMessageTarget() {}
virtual void Update(wxString message) {} virtual void Update(const wxString &message) override {}
}; };
/// Displays messages from a command in a wxMessageBox /// Displays messages from a command in a wxMessageBox
@ -101,7 +101,7 @@ class MessageBoxTarget : public CommandMessageTarget
{ {
public: public:
virtual ~MessageBoxTarget() {} virtual ~MessageBoxTarget() {}
virtual void Update(wxString message) virtual void Update(const wxString &message) override
{ {
wxMessageBox(message); wxMessageBox(message);
} }
@ -116,7 +116,7 @@ public:
StatusBarTarget(wxStatusBar &sb) StatusBarTarget(wxStatusBar &sb)
: mStatus(sb) : mStatus(sb)
{} {}
virtual void Update(wxString message) virtual void Update(const wxString &message) override
{ {
mStatus.SetStatusText(message, 0); mStatus.SetStatusText(message, 0);
} }
@ -135,7 +135,7 @@ public:
{ {
mResponseQueue.AddResponse(wxString(wxT("\n"))); mResponseQueue.AddResponse(wxString(wxT("\n")));
} }
virtual void Update(wxString message) virtual void Update(const wxString &message) override
{ {
mResponseQueue.AddResponse(message); mResponseQueue.AddResponse(message);
} }
@ -158,7 +158,7 @@ public:
delete m1; delete m1;
delete m2; delete m2;
} }
virtual void Update(wxString message) virtual void Update(const wxString &message) override
{ {
m1->Update(message); m1->Update(message);
m2->Update(message); m2->Update(message);
@ -220,12 +220,12 @@ public:
if (mProgressTarget) if (mProgressTarget)
mProgressTarget->Update(completed); mProgressTarget->Update(completed);
} }
void Status(wxString status) void Status(const wxString &status)
{ {
if (mStatusTarget) if (mStatusTarget)
mStatusTarget->Update(status); mStatusTarget->Update(status);
} }
void Error(wxString message) void Error(const wxString &message)
{ {
if (mErrorTarget) if (mErrorTarget)
mErrorTarget->Update(message); mErrorTarget->Update(message);

View File

@ -152,7 +152,7 @@ static void Yield()
} }
} }
void ScreenshotCommand::Capture(wxString filename, void ScreenshotCommand::Capture(const wxString &filename,
wxWindow *window, wxWindow *window,
int x, int y, int width, int height, int x, int y, int width, int height,
bool bg) bool bg)
@ -226,7 +226,7 @@ void ScreenshotCommand::Capture(wxString filename,
::wxBell(); ::wxBell();
} }
void ScreenshotCommand::CaptureToolbar(ToolManager *man, int type, wxString name) void ScreenshotCommand::CaptureToolbar(ToolManager *man, int type, const wxString &name)
{ {
bool visible = man->IsVisible(type); bool visible = man->IsVisible(type);
if (!visible) { if (!visible) {
@ -251,7 +251,7 @@ void ScreenshotCommand::CaptureToolbar(ToolManager *man, int type, wxString name
} }
} }
void ScreenshotCommand::CaptureDock(wxWindow *win, wxString fileName) void ScreenshotCommand::CaptureDock(wxWindow *win, const wxString &fileName)
{ {
int x = 0, y = 0; int x = 0, y = 0;
int width, height; int width, height;
@ -311,7 +311,7 @@ Command *ScreenshotCommandType::Create(CommandOutputTarget *target)
return new ScreenshotCommand(*this, target); return new ScreenshotCommand(*this, target);
} }
wxString ScreenshotCommand::MakeFileName(wxString path, wxString basename) wxString ScreenshotCommand::MakeFileName(const wxString &path, const wxString &basename)
{ {
wxFileName prefixPath; wxFileName prefixPath;
prefixPath.AssignDir(path); prefixPath.AssignDir(path);

View File

@ -40,15 +40,15 @@ private:
bool mBackground; bool mBackground;
wxColour mBackColor; wxColour mBackColor;
wxString MakeFileName(wxString path, wxString basename); wxString MakeFileName(const wxString &path, const wxString &basename);
wxRect GetBackgroundRect(); wxRect GetBackgroundRect();
void Capture(wxString basename, void Capture(const wxString &basename,
wxWindow *window, wxWindow *window,
int x, int y, int width, int height, int x, int y, int width, int height,
bool bg = false); bool bg = false);
void CaptureToolbar(ToolManager *man, int type, wxString name); void CaptureToolbar(ToolManager *man, int type, const wxString &name);
void CaptureDock(wxWindow *win, wxString fileName); void CaptureDock(wxWindow *win, const wxString &fileName);
public: public:
wxTopLevelWindow *GetFrontWindow(AudacityProject *project); wxTopLevelWindow *GetFrontWindow(AudacityProject *project);

View File

@ -75,7 +75,7 @@ bool SetProjectInfoCommand::Apply(CommandExecutionContext context)
// *********************** Private Methods ******************* // *********************** Private Methods *******************
void SetProjectInfoCommand::SetAllTracksParam(TrackList *projTracks, wxString boolValueStr, Setter functPtrToSetter) void SetProjectInfoCommand::SetAllTracksParam(TrackList *projTracks, const wxString &boolValueStr, Setter functPtrToSetter)
{ {
unsigned int i=0; unsigned int i=0;
TrackListIterator iter(projTracks); TrackListIterator iter(projTracks);

View File

@ -48,7 +48,7 @@ private:
typedef void (SetProjectInfoCommand::*Setter)(Track *trk, bool setting) const; typedef void (SetProjectInfoCommand::*Setter)(Track *trk, bool setting) const;
// Uses the Function pointer to set a particular parameter within a loop of otherwise duplicate code // Uses the Function pointer to set a particular parameter within a loop of otherwise duplicate code
void SetAllTracksParam(TrackList *projTracks, wxString boolValueStr, Setter functPtrToSetter); void SetAllTracksParam(TrackList *projTracks, const wxString &boolValueStr, Setter functPtrToSetter);
// Function pointer to accessing a particular parameter within a loop of otherwise duplicate code // Function pointer to accessing a particular parameter within a loop of otherwise duplicate code
void setSelected(Track *trk, bool setting) const; void setSelected(Track *trk, bool setting) const;