Skip to content

Commit 5a26c1f

Browse files
authored
Use string_view inputs for conversion functions (flutter#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.
1 parent 0d62a56 commit 5a26c1f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

shell/platform/windows/string_conversion.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace flutter {
1010

11-
std::string Utf8FromUtf16(const std::wstring& utf16_string) {
11+
std::string Utf8FromUtf16(const std::wstring_view utf16_string) {
1212
if (utf16_string.empty()) {
1313
return std::string();
1414
}
@@ -30,7 +30,7 @@ std::string Utf8FromUtf16(const std::wstring& utf16_string) {
3030
return utf8_string;
3131
}
3232

33-
std::wstring Utf16FromUtf8(const std::string& utf8_string) {
33+
std::wstring Utf16FromUtf8(const std::string_view utf8_string) {
3434
if (utf8_string.empty()) {
3535
return std::wstring();
3636
}

shell/platform/windows/string_conversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ namespace flutter {
1111

1212
// Converts a string from UTF-16 to UTF-8. Returns an empty string if the
1313
// input is not valid UTF-16.
14-
std::string Utf8FromUtf16(const std::wstring& utf16_string);
14+
std::string Utf8FromUtf16(const std::wstring_view utf16_string);
1515

1616
// Converts a string from UTF-8 to UTF-16. Returns an empty string if the
1717
// input is not valid UTF-8.
18-
std::wstring Utf16FromUtf8(const std::string& utf8_string);
18+
std::wstring Utf16FromUtf8(const std::string_view utf8_string);
1919

2020
} // namespace flutter
2121

0 commit comments

Comments
 (0)