Common/SettingsHandler: Use std::string_view more
We don't need to enforce the use of std::string instances with AddSetting(). We can accept views and only construct one string, rather than three temporaries.
This commit is contained in:
parent
04b9f6c28d
commit
88a973131c
|
@ -92,12 +92,12 @@ void SettingsHandler::Reset()
|
||||||
m_buffer = {};
|
m_buffer = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsHandler::AddSetting(const std::string& key, const std::string& value)
|
void SettingsHandler::AddSetting(std::string_view key, std::string_view value)
|
||||||
{
|
{
|
||||||
WriteLine(key + '=' + value + "\r\n");
|
WriteLine(fmt::format("{}={}\r\n", key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsHandler::WriteLine(const std::string& str)
|
void SettingsHandler::WriteLine(std::string_view str)
|
||||||
{
|
{
|
||||||
const u32 old_position = m_position;
|
const u32 old_position = m_position;
|
||||||
const u32 old_key = m_key;
|
const u32 old_key = m_key;
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
SettingsHandler();
|
SettingsHandler();
|
||||||
explicit SettingsHandler(Buffer&& buffer);
|
explicit SettingsHandler(Buffer&& buffer);
|
||||||
|
|
||||||
void AddSetting(const std::string& key, const std::string& value);
|
void AddSetting(std::string_view key, std::string_view value);
|
||||||
|
|
||||||
const Buffer& GetBytes() const;
|
const Buffer& GetBytes() const;
|
||||||
void SetBytes(Buffer&& buffer);
|
void SetBytes(Buffer&& buffer);
|
||||||
|
@ -38,7 +38,7 @@ public:
|
||||||
static std::string GenerateSerialNumber();
|
static std::string GenerateSerialNumber();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void WriteLine(const std::string& str);
|
void WriteLine(std::string_view str);
|
||||||
void WriteByte(u8 b);
|
void WriteByte(u8 b);
|
||||||
|
|
||||||
std::array<u8, SETTINGS_SIZE> m_buffer;
|
std::array<u8, SETTINGS_SIZE> m_buffer;
|
||||||
|
|
Loading…
Reference in New Issue