diff options
author | Loren Shih <seraph@lindenlab.com> | 2010-07-27 10:24:53 -0400 |
---|---|---|
committer | Loren Shih <seraph@lindenlab.com> | 2010-07-27 10:24:53 -0400 |
commit | a3328658725dd12efbb1a9107e4c6f0612772c12 (patch) | |
tree | cc9707083f3cef32a92a481ffbae5b0a7ef92630 /indra/llcommon | |
parent | 34ab18d0c2f7de57e42ded0c3d94ee0fec17da28 (diff) | |
parent | d55264bf13520fc7adab347565ee13cc30fc8656 (diff) |
automated merge
Diffstat (limited to 'indra/llcommon')
-rw-r--r-- | indra/llcommon/llstring.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp index 804c00fd60..2693c0e22b 100644 --- a/indra/llcommon/llstring.cpp +++ b/indra/llcommon/llstring.cpp @@ -672,16 +672,23 @@ std::string ll_convert_wide_to_string(const wchar_t* in, unsigned int code_page) wchar_t* ll_convert_string_to_wide(const std::string& in, unsigned int code_page) { - int output_str_len = MultiByteToWideChar(code_page, 0, in.c_str(), in.length(), NULL, 0); + // From review: + // We can preallocate a wide char buffer that is the same length (in wchar_t elements) as the utf8 input, + // plus one for a null terminator, and be guaranteed to not overflow. + + // Normally, I'd call that sort of thing premature optimization, + // but we *are* seeing string operations taking a bunch of time, especially when constructing widgets. +// int output_str_len = MultiByteToWideChar(code_page, 0, in.c_str(), in.length(), NULL, 0); // reserve place to NULL terminator + int output_str_len = in.length(); wchar_t* w_out = new wchar_t[output_str_len + 1]; memset(w_out, 0, output_str_len + 1); - MultiByteToWideChar (code_page, 0, in.c_str(), in.length(), w_out, output_str_len); + int real_output_str_len = MultiByteToWideChar (code_page, 0, in.c_str(), in.length(), w_out, output_str_len); //looks like MultiByteToWideChar didn't add null terminator to converted string, see EXT-4858. - w_out[output_str_len] = 0; + w_out[real_output_str_len] = 0; return w_out; } @@ -689,7 +696,7 @@ wchar_t* ll_convert_string_to_wide(const std::string& in, unsigned int code_page std::string ll_convert_string_to_utf8_string(const std::string& in) { wchar_t* w_mesg = ll_convert_string_to_wide(in, CP_ACP); - std::string out_utf8 = ll_convert_wide_to_string(w_mesg, CP_UTF8); + std::string out_utf8(ll_convert_wide_to_string(w_mesg, CP_UTF8)); delete[] w_mesg; return out_utf8; |