Skip to content

Commit

Permalink
PSF: Fix string_view optimization
Browse files Browse the repository at this point in the history
Avoid redundant copies of std::string.
  • Loading branch information
elad335 committed Apr 9, 2021
1 parent 4a4918b commit 0f97fe6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions rpcs3/Loader/PSF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/Loader/PSF.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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; }
Expand Down Expand Up @@ -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};
}
}

0 comments on commit 0f97fe6

Please sign in to comment.