From 20ea6894a2660c453c3255a66aa9f7e24cf97ec8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 12 Jul 2002 18:14:39 +0000 Subject: [PATCH] don't write the strings to the stream one char at a time, it's *horribly* slow git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16150 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/txtstrm.cpp | 50 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/common/txtstrm.cpp b/src/common/txtstrm.cpp index f90acd13fd..14b8e4a626 100644 --- a/src/common/txtstrm.cpp +++ b/src/common/txtstrm.cpp @@ -412,33 +412,41 @@ void wxTextOutputStream::WriteDouble(double d) void wxTextOutputStream::WriteString(const wxString& string) { - for (size_t i = 0; i < string.Len(); i++) + size_t len = string.length(); + + wxString out; + out.reserve(len); + + for ( size_t i = 0; i < len; i++ ) { - wxChar c = string[i]; - if (c == wxT('\n')) + const wxChar c = string[i]; + if ( c == wxT('\n') ) { - if (m_mode == wxEOL_DOS) - { - c = wxT('\r'); - m_output.Write( (const void*)(&c), sizeof(wxChar) ); - c = wxT('\n'); - m_output.Write( (const void*)(&c), sizeof(wxChar) ); - } else - if (m_mode == wxEOL_MAC) + switch ( m_mode ) { - c = wxT('\r'); - m_output.Write( (const void*)(&c), sizeof(wxChar) ); - } else - { - c = wxT('\n'); - m_output.Write( (const void*)(&c), sizeof(wxChar) ); + case wxEOL_DOS: + out << _T("\r\n"); + continue; + + case wxEOL_MAC: + out << _T('\r'); + continue; + + default: + wxFAIL_MSG( _T("unknown EOL mode in wxTextOutputStream") ); + // fall through + + case wxEOL_UNIX: + // don't treat '\n' specially + ; } } - else - { - m_output.Write( (const void*)(&c), sizeof(wxChar) ); - } + + out << c; } + + // NB: we don't need to write the trailing NUL here + m_output.Write(out.c_str(), out.length() * sizeof(wxChar)); } wxTextOutputStream& wxTextOutputStream::operator<<(const wxChar *string) -- 2.45.2