diff options
| author | Mike Antipov <mantipov@productengine.com> | 2010-07-26 11:44:50 +0300 | 
|---|---|---|
| committer | Mike Antipov <mantipov@productengine.com> | 2010-07-26 11:44:50 +0300 | 
| commit | 8e461d902ed12b6a054cb92a19835d7af2a31474 (patch) | |
| tree | 21d4598a09497b120b042999071b57f0a335e39d /indra | |
| parent | 2e9671a8a8ec0a8897945c96aa62c77ad245abac (diff) | |
EXT-8318 FIX IMPROVED Code is refactored - avoid using of a separate call of the MultiByteToWideChar to get length of output string.
Assumprion is: wide char buffer requires not more than input string length plus one for a null terminator.
Reviewed by Richard Nelson at https://codereview.productengine.com/secondlife/r/775/
--HG--
branch : product-engine
Diffstat (limited to 'indra')
| -rw-r--r-- | indra/llcommon/llstring.cpp | 13 | 
1 files changed, 10 insertions, 3 deletions
| diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp index 852a57af85..671b0a108c 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;  } | 
