Skip to content
Permalink
Browse files

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.
  • Loading branch information...
lioncash committed Jun 7, 2019
1 parent 32427af commit 6e9329455c30d75c96c3f21bb2e02185a1807e07
Showing with 8 additions and 7 deletions.
  1. +5 −5 Source/Core/Core/DSP/LabelMap.cpp
  2. +3 −2 Source/Core/Core/DSP/LabelMap.h
@@ -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; });
@@ -6,6 +6,7 @@

#include <optional>
#include <string>
#include <string_view>
#include <vector>

#include "Common/CommonTypes.h"
@@ -27,8 +28,8 @@ class LabelMap
~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();

0 comments on commit 6e93294

Please sign in to comment.
You can’t perform that action at this time.