From c43494318e4c2e6749ab1790f8847a696a6d6d4d Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Fri, 7 May 2021 22:18:39 -0700 Subject: [PATCH] Use string_view inputs for conversion functions 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. --- shell/platform/windows/string_conversion.cc | 4 ++-- shell/platform/windows/string_conversion.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/shell/platform/windows/string_conversion.cc b/shell/platform/windows/string_conversion.cc index 1519337a0acba..d3ab3143ea7f6 100644 --- a/shell/platform/windows/string_conversion.cc +++ b/shell/platform/windows/string_conversion.cc @@ -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(); } diff --git a/shell/platform/windows/string_conversion.h b/shell/platform/windows/string_conversion.h index ce84be2f46f85..b79aed4711072 100644 --- a/shell/platform/windows/string_conversion.h +++ b/shell/platform/windows/string_conversion.h @@ -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