Use string_view inputs for conversion functions (flutter/engine#26031)

This offers a small improvement in performance in cases where the input
is a raw char* or wchar_t* string due to not having to perform an
implicit conversion to std::string/std::wstring.

Code cleanup covered by existing tests, which already use raw C strings.
This commit is contained in:
Chris Bracken 2021-05-08 11:17:41 -07:00 committed by GitHub
parent a10ad99348
commit 83dcf51c7b
2 changed files with 4 additions and 4 deletions

View File

@ -8,7 +8,7 @@
namespace flutter {
std::string Utf8FromUtf16(const std::wstring& utf16_string) {
std::string Utf8FromUtf16(const std::wstring_view utf16_string) {
if (utf16_string.empty()) {
return std::string();
}
@ -30,7 +30,7 @@ std::string Utf8FromUtf16(const std::wstring& utf16_string) {
return utf8_string;
}
std::wstring Utf16FromUtf8(const std::string& utf8_string) {
std::wstring Utf16FromUtf8(const std::string_view utf8_string) {
if (utf8_string.empty()) {
return std::wstring();
}

View File

@ -11,11 +11,11 @@ namespace flutter {
// Converts a string from UTF-16 to UTF-8. Returns an empty string if the
// input is not valid UTF-16.
std::string Utf8FromUtf16(const std::wstring& utf16_string);
std::string Utf8FromUtf16(const std::wstring_view utf16_string);
// Converts a string from UTF-8 to UTF-16. Returns an empty string if the
// input is not valid UTF-8.
std::wstring Utf16FromUtf8(const std::string& utf8_string);
std::wstring Utf16FromUtf8(const std::string_view utf8_string);
} // namespace flutter