Common/Watches: std::move strings where applicable

Allows calling code to move the std::string into the Watch instances,
avoiding copies.
This commit is contained in:
Lioncash
2019-07-08 17:28:07 -04:00
parent 0a7395bfba
commit bc8778203e
7 changed files with 35 additions and 35 deletions

View File

@ -9,12 +9,12 @@
namespace Common::Debug
{
Watch::Watch(u32 address_, const std::string& name_, Watch::State is_enabled_)
: address(address_), name(name_), is_enabled(is_enabled_)
Watch::Watch(u32 address_, std::string name_, State is_enabled_)
: address(address_), name(std::move(name_)), is_enabled(is_enabled_)
{
}
std::size_t Watches::SetWatch(u32 address, const std::string& name)
std::size_t Watches::SetWatch(u32 address, std::string name)
{
const std::size_t size = m_watches.size();
for (std::size_t index = 0; index < size; index++)
@ -25,7 +25,7 @@ std::size_t Watches::SetWatch(u32 address, const std::string& name)
return index;
}
}
m_watches.emplace_back(address, name, Watch::State::Enabled);
m_watches.emplace_back(address, std::move(name), Watch::State::Enabled);
return size;
}
@ -46,10 +46,10 @@ void Watches::UnsetWatch(u32 address)
m_watches.end());
}
void Watches::UpdateWatch(std::size_t index, u32 address, const std::string& name)
void Watches::UpdateWatch(std::size_t index, u32 address, std::string name)
{
m_watches[index].address = address;
m_watches[index].name = name;
m_watches[index].name = std::move(name);
}
void Watches::UpdateWatchAddress(std::size_t index, u32 address)
@ -57,9 +57,9 @@ void Watches::UpdateWatchAddress(std::size_t index, u32 address)
m_watches[index].address = address;
}
void Watches::UpdateWatchName(std::size_t index, const std::string& name)
void Watches::UpdateWatchName(std::size_t index, std::string name)
{
m_watches[index].name = name;
m_watches[index].name = std::move(name);
}
void Watches::EnableWatch(std::size_t index)

View File

@ -24,19 +24,19 @@ struct Watch
std::string name;
State is_enabled;
Watch(u32 address, const std::string& name, State is_enabled);
Watch(u32 address, std::string name, State is_enabled);
};
class Watches
{
public:
std::size_t SetWatch(u32 address, const std::string& name);
std::size_t SetWatch(u32 address, std::string name);
const Watch& GetWatch(std::size_t index) const;
const std::vector<Watch>& GetWatches() const;
void UnsetWatch(u32 address);
void UpdateWatch(std::size_t index, u32 address, const std::string& name);
void UpdateWatch(std::size_t index, u32 address, std::string name);
void UpdateWatchAddress(std::size_t index, u32 address);
void UpdateWatchName(std::size_t index, const std::string& name);
void UpdateWatchName(std::size_t index, std::string name);
void EnableWatch(std::size_t index);
void DisableWatch(std::size_t index);
bool HasEnabledWatch(u32 address) const;

View File

@ -22,13 +22,13 @@ protected:
public:
// Watches
virtual std::size_t SetWatch(u32 address, const std::string& name = "") = 0;
virtual std::size_t SetWatch(u32 address, std::string name = "") = 0;
virtual const Common::Debug::Watch& GetWatch(std::size_t index) const = 0;
virtual const std::vector<Common::Debug::Watch>& GetWatches() const = 0;
virtual void UnsetWatch(u32 address) = 0;
virtual void UpdateWatch(std::size_t index, u32 address, const std::string& name) = 0;
virtual void UpdateWatch(std::size_t index, u32 address, std::string name) = 0;
virtual void UpdateWatchAddress(std::size_t index, u32 address) = 0;
virtual void UpdateWatchName(std::size_t index, const std::string& name) = 0;
virtual void UpdateWatchName(std::size_t index, std::string name) = 0;
virtual void EnableWatch(std::size_t index) = 0;
virtual void DisableWatch(std::size_t index) = 0;
virtual bool HasEnabledWatch(u32 address) const = 0;