To make the string_view constructor worthwhile, I changed assign to not allocate a temporary std::string and to operate on const char* + size_t instead. I then also added a constructor for string literals so the const char* constructor doesn't get used for those, this prevents a call to strlen.
I also prevented out of bound accesses that would be caused by invalid UTF-8 sequences.
If MyGUI wants to switch to C++17, the const char*, const std::string&, and const char*, size_t constructors could straight up be replaced by a single string_view constructor.
This PR changes
UString
to have astring_view
constructor when compiling with C++17. The change to CMakeLists is because of https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170To make the string_view constructor worthwhile, I changed
assign
to not allocate a temporarystd::string
and to operate onconst char*
+size_t
instead. I then also added a constructor for string literals so theconst char*
constructor doesn't get used for those, this prevents a call tostrlen
.I also prevented out of bound accesses that would be caused by invalid UTF-8 sequences.
If MyGUI wants to switch to C++17, the
const char*
,const std::string&
, andconst char*, size_t
constructors could straight up be replaced by a single string_view constructor.