diff --git a/src/common/sstream.cpp b/src/common/sstream.cpp index a67cd23152..2ab8557bbc 100644 --- a/src/common/sstream.cpp +++ b/src/common/sstream.cpp @@ -136,10 +136,16 @@ wxStringOutputStream::wxStringOutputStream(wxString *pString, wxMBConv& conv) { m_str = pString ? pString : &m_strInternal; -#if wxUSE_UNICODE_WCHAR - m_pos = m_conv.FromWChar(NULL, 0, m_str->wc_str(), m_str->length()); -#elif wxUSE_UNICODE_UTF8 - m_pos = m_str->utf8_length(); +#if wxUSE_UNICODE + // We can avoid doing the conversion in the common case of using UTF-8 + // conversion in UTF-8 build, as it is exactly the same as the string + // length anyhow in this case. +#if wxUSE_UNICODE_UTF8 + if ( conv.IsUTF8() ) + m_pos = m_str->utf8_length(); + else +#endif // wxUSE_UNICODE_UTF8 + m_pos = m_conv.FromWChar(NULL, 0, m_str->wc_str(), m_str->length()); #else // !wxUSE_UNICODE m_pos = m_str->length(); #endif // wxUSE_UNICODE/!wxUSE_UNICODE