DSP/LabelMap: std::move std::string instances where applicable

We can std::move the std::string parameter in Label's constructor,
allowing the constructor to be moved into in calling code.

We can cascade this outwards in the interface as well.
This commit is contained in:
Lioncash 2019-06-07 17:42:08 -04:00
parent 32427af79e
commit 6e9329455c
2 changed files with 8 additions and 7 deletions

View File

@ -14,8 +14,8 @@ namespace DSP
{
struct LabelMap::Label
{
Label(const std::string& lbl, s32 address, LabelType ltype)
: name(lbl), addr(address), type(ltype)
Label(std::string lbl, s32 address, LabelType ltype)
: name(std::move(lbl)), addr(address), type(ltype)
{
}
std::string name;
@ -42,7 +42,7 @@ void LabelMap::RegisterDefaults()
}
}
void LabelMap::RegisterLabel(const std::string& label, u16 lval, LabelType type)
void LabelMap::RegisterLabel(std::string label, u16 lval, LabelType type)
{
const std::optional<u16> old_value = GetLabelValue(label);
if (old_value && old_value != lval)
@ -51,10 +51,10 @@ void LabelMap::RegisterLabel(const std::string& label, u16 lval, LabelType type)
*old_value);
DeleteLabel(label);
}
labels.emplace_back(label, lval, type);
labels.emplace_back(std::move(label), lval, type);
}
void LabelMap::DeleteLabel(const std::string& label)
void LabelMap::DeleteLabel(std::string_view label)
{
const auto iter = std::find_if(labels.cbegin(), labels.cend(),
[&label](const auto& entry) { return entry.name == label; });

View File

@ -6,6 +6,7 @@
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include "Common/CommonTypes.h"
@ -27,8 +28,8 @@ public:
~LabelMap();
void RegisterDefaults();
void RegisterLabel(const std::string& label, u16 lval, LabelType type = LABEL_VALUE);
void DeleteLabel(const std::string& label);
void RegisterLabel(std::string label, u16 lval, LabelType type = LABEL_VALUE);
void DeleteLabel(std::string_view label);
std::optional<u16> GetLabelValue(const std::string& label, LabelType type = LABEL_ANY) const;
void Clear();