PSF: Fix string_view optimization

Avoid redundant copies of std::string.
This commit is contained in:
Eladash 2021-03-31 08:20:38 +03:00 committed by Ivan
parent a8d5a8734a
commit a3e8a61547
2 changed files with 6 additions and 6 deletions

View file

@ -59,7 +59,7 @@ namespace psf
};
entry::entry(format type, u32 max_size, const std::string& value)
entry::entry(format type, u32 max_size, std::string_view value)
: m_type(type)
, m_max_size(max_size)
, m_value_string(value)
@ -91,7 +91,7 @@ namespace psf
return m_value_integer;
}
entry& entry::operator =(const std::string& value)
entry& entry::operator =(std::string_view value)
{
ensure(m_type == format::string || m_type == format::array);
m_value_string = value;

View file

@ -36,7 +36,7 @@ namespace psf
public:
// Construct string entry, assign the value
entry(format type, u32 max_size, const std::string& value = {});
entry(format type, u32 max_size, std::string_view value);
// Construct integer entry, assign the value
entry(u32 value);
@ -46,7 +46,7 @@ namespace psf
const std::string& as_string() const;
u32 as_integer() const;
entry& operator =(const std::string& value);
entry& operator =(std::string_view value);
entry& operator =(u32 value);
format type() const { return m_type; }
@ -100,12 +100,12 @@ namespace psf
// Make string entry
inline entry string(u32 max_size, std::string_view value)
{
return {format::string, max_size, std::string(value)};
return {format::string, max_size, value};
}
// Make array entry
inline entry array(u32 max_size, std::string_view value)
{
return {format::array, max_size, std::string(value)};
return {format::array, max_size, value};
}
}