mirror of https://github.com/AxioDL/metaforce.git
hecl/hecl: Slightly improve resource usage within string conv operator+ funcs
We already construct a std::string instance, so we can just append to it instead of creating another temporary with std::string's operator+. We also change this to append using the string view getter functions, as this allows the appending process to do less work. When a pointer is passed in, a strlen call would need to be performed in order to determine the total characters to append. However, we already know the size (via the string view).
This commit is contained in:
parent
c513a4b61f
commit
c7aae83a75
|
@ -115,7 +115,9 @@ public:
|
|||
const char* c_str() const { return m_utf8.c_str(); }
|
||||
std::string operator+(std::string_view other) const { return m_utf8 + other.data(); }
|
||||
};
|
||||
inline std::string operator+(std::string_view lhs, const SystemUTF8Conv& rhs) { return std::string(lhs) + rhs.c_str(); }
|
||||
inline std::string operator+(std::string_view lhs, const SystemUTF8Conv& rhs) {
|
||||
return std::string(lhs).append(rhs.str());
|
||||
}
|
||||
class SystemStringConv {
|
||||
std::wstring m_sys;
|
||||
|
||||
|
@ -126,7 +128,7 @@ public:
|
|||
std::wstring operator+(const std::wstring_view other) const { return m_sys + other.data(); }
|
||||
};
|
||||
inline std::wstring operator+(std::wstring_view lhs, const SystemStringConv& rhs) {
|
||||
return std::wstring(lhs) + rhs.c_str();
|
||||
return std::wstring(lhs).append(rhs.sys_str());
|
||||
}
|
||||
#else
|
||||
class SystemUTF8Conv {
|
||||
|
@ -136,9 +138,11 @@ public:
|
|||
explicit SystemUTF8Conv(SystemStringView str) : m_utf8(str) {}
|
||||
std::string_view str() const { return m_utf8; }
|
||||
const char* c_str() const { return m_utf8.data(); }
|
||||
std::string operator+(std::string_view other) const { return std::string(m_utf8) + other.data(); }
|
||||
std::string operator+(std::string_view other) const { return std::string(m_utf8).append(other); }
|
||||
};
|
||||
inline std::string operator+(std::string_view lhs, const SystemUTF8Conv& rhs) { return std::string(lhs) + rhs.c_str(); }
|
||||
inline std::string operator+(std::string_view lhs, const SystemUTF8Conv& rhs) {
|
||||
return std::string(lhs).append(rhs.str());
|
||||
}
|
||||
class SystemStringConv {
|
||||
std::string_view m_sys;
|
||||
|
||||
|
@ -146,10 +150,10 @@ public:
|
|||
explicit SystemStringConv(std::string_view str) : m_sys(str) {}
|
||||
SystemStringView sys_str() const { return m_sys; }
|
||||
const SystemChar* c_str() const { return m_sys.data(); }
|
||||
std::string operator+(std::string_view other) const { return std::string(m_sys) + other.data(); }
|
||||
std::string operator+(std::string_view other) const { return std::string(m_sys).append(other); }
|
||||
};
|
||||
inline std::string operator+(std::string_view lhs, const SystemStringConv& rhs) {
|
||||
return std::string(lhs) + rhs.c_str();
|
||||
return std::string(lhs).append(rhs.sys_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue