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
This commit is contained in:
Vadim Zeitlin
2007-07-20 01:03:33 +00:00
parent c225b981b6
commit cdbcd6c12f

View File

@@ -1961,13 +1961,28 @@ int CompareGroups(wxFileConfigGroup *p1, wxFileConfigGroup *p2)
static wxString FilterInValue(const wxString& str) static wxString FilterInValue(const wxString& str)
{ {
wxString strResult; wxString strResult;
strResult.Alloc(str.Len()); 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++ ) { wxString::const_iterator i = str.begin();
if ( str[n] == wxT('\\') ) { const bool bQuoted = *i == '"';
switch ( str[++n].GetValue() ) { if ( bQuoted )
++i;
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;
}
switch ( (*i).GetValue() )
{
case wxT('n'): case wxT('n'):
strResult += wxT('\n'); strResult += wxT('\n');
break; break;
@@ -1989,12 +2004,16 @@ static wxString FilterInValue(const wxString& str)
break; break;
} }
} }
else { else // not a backslash
if ( str[n] != wxT('"') || !bQuoted ) {
strResult += str[n]; if ( *i != wxT('"') || !bQuoted )
else if ( n != str.Len() - 1 ) { {
strResult += *i;
}
else if ( i != end - 1 )
{
wxLogWarning(_("unexpected \" at position %d in '%s'."), wxLogWarning(_("unexpected \" at position %d in '%s'."),
n, str.c_str()); i - str.begin(), str.c_str());
} }
//else: it's the last quote of a quoted string, ok //else: it's the last quote of a quoted string, ok
} }