Index: base/strings/utf_string_conversions.cc |
diff --git a/base/strings/utf_string_conversions.cc b/base/strings/utf_string_conversions.cc |
index f13ed1bb9c61fc6c2211a488bd3568047c5e3fc1..9d520fa5ecf0841a4379a4062de65767bf22e9fd 100644 |
--- a/base/strings/utf_string_conversions.cc |
+++ b/base/strings/utf_string_conversions.cc |
@@ -56,13 +56,23 @@ std::string WideToUTF8(const std::wstring& wide) { |
} |
bool UTF8ToWide(const char* src, size_t src_len, std::wstring* output) { |
- PrepareForUTF16Or32Output(src, src_len, output); |
- return ConvertUnicode(src, src_len, output); |
+ if (IsStringASCII(StringPiece(src, src_len))) { |
+ output->assign(src, src + src_len); |
+ return true; |
+ } else { |
+ PrepareForUTF16Or32Output(src, src_len, output); |
+ return ConvertUnicode(src, src_len, output); |
+ } |
} |
std::wstring UTF8ToWide(const StringPiece& utf8) { |
+ if (IsStringASCII(utf8)) { |
+ return std::wstring(utf8.begin(), utf8.end()); |
+ } |
+ |
std::wstring ret; |
- UTF8ToWide(utf8.data(), utf8.length(), &ret); |
+ PrepareForUTF16Or32Output(utf8.data(), utf8.length(), &ret); |
+ ConvertUnicode(utf8.data(), utf8.length(), &ret); |
return ret; |
} |
@@ -126,15 +136,25 @@ std::wstring UTF16ToWide(const string16& utf16) { |
#if defined(WCHAR_T_IS_UTF32) |
bool UTF8ToUTF16(const char* src, size_t src_len, string16* output) { |
- PrepareForUTF16Or32Output(src, src_len, output); |
- return ConvertUnicode(src, src_len, output); |
+ if (IsStringASCII(StringPiece(src, src_len))) { |
+ output->assign(src, src + src_len); |
+ return true; |
+ } else { |
+ PrepareForUTF16Or32Output(src, src_len, output); |
+ return ConvertUnicode(src, src_len, output); |
+ } |
} |
string16 UTF8ToUTF16(const StringPiece& utf8) { |
+ if (IsStringASCII(utf8)) { |
+ return string16(utf8.begin(), utf8.end()); |
+ } |
+ |
string16 ret; |
+ PrepareForUTF16Or32Output(utf8.data(), utf8.length(), &ret); |
// Ignore the success flag of this call, it will do the best it can for |
// invalid input, which is what we want here. |
- UTF8ToUTF16(utf8.data(), utf8.length(), &ret); |
+ ConvertUnicode(utf8.data(), utf8.length(), &ret); |
return ret; |
} |