From cdbcd6c12f499b58f7d92904b45690912938a98f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 20 Jul 2007 01:03:33 +0000 Subject: [PATCH] rewrite FilterInValue() using iterators, this results iin 12x performance improvement in UTF-8 build git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47577 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/fileconf.cpp | 85 +++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index 0334138412..ab3c4a0f49 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -1960,47 +1960,66 @@ int CompareGroups(wxFileConfigGroup *p1, wxFileConfigGroup *p2) // undo FilterOutValue static wxString FilterInValue(const wxString& str) { - wxString strResult; - strResult.Alloc(str.Len()); + wxString strResult; + if ( str.empty() ) + return strResult; - bool bQuoted = !str.empty() && str[0] == '"'; + strResult.reserve(str.length()); - for ( size_t n = bQuoted ? 1 : 0; n < str.Len(); n++ ) { - if ( str[n] == wxT('\\') ) { - switch ( str[++n].GetValue() ) { - case wxT('n'): - strResult += wxT('\n'); - break; + wxString::const_iterator i = str.begin(); + const bool bQuoted = *i == '"'; + if ( bQuoted ) + ++i; - case wxT('r'): - strResult += wxT('\r'); - break; + for ( const wxString::const_iterator end = str.end(); i != end; ++i ) + { + if ( *i == wxT('\\') ) + { + if ( ++i == end ) + { + wxLogWarning(_("trailing backslash ignored in '%s'"), str.c_str()); + break; + } - case wxT('t'): - strResult += wxT('\t'); - break; + switch ( (*i).GetValue() ) + { + case wxT('n'): + strResult += wxT('\n'); + break; - case wxT('\\'): - strResult += wxT('\\'); - break; + case wxT('r'): + strResult += wxT('\r'); + break; - case wxT('"'): - strResult += wxT('"'); - break; - } - } - else { - if ( str[n] != wxT('"') || !bQuoted ) - strResult += str[n]; - else if ( n != str.Len() - 1 ) { - wxLogWarning(_("unexpected \" at position %d in '%s'."), - n, str.c_str()); - } - //else: it's the last quote of a quoted string, ok + case wxT('t'): + strResult += wxT('\t'); + break; + + case wxT('\\'): + strResult += wxT('\\'); + break; + + case wxT('"'): + strResult += wxT('"'); + break; + } + } + else // not a backslash + { + if ( *i != wxT('"') || !bQuoted ) + { + strResult += *i; + } + else if ( i != end - 1 ) + { + wxLogWarning(_("unexpected \" at position %d in '%s'."), + i - str.begin(), str.c_str()); + } + //else: it's the last quote of a quoted string, ok + } } - } - return strResult; + return strResult; } // quote the string before writing it to file -- 2.45.2