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

@ -1960,47 +1960,66 @@ int CompareGroups(wxFileConfigGroup *p1, wxFileConfigGroup *p2)
// undo FilterOutValue // undo FilterOutValue
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 )
case wxT('n'): ++i;
strResult += wxT('\n');
break;
case wxT('r'): for ( const wxString::const_iterator end = str.end(); i != end; ++i )
strResult += wxT('\r'); {
break; if ( *i == wxT('\\') )
{
if ( ++i == end )
{
wxLogWarning(_("trailing backslash ignored in '%s'"), str.c_str());
break;
}
case wxT('t'): switch ( (*i).GetValue() )
strResult += wxT('\t'); {
break; case wxT('n'):
strResult += wxT('\n');
break;
case wxT('\\'): case wxT('r'):
strResult += wxT('\\'); strResult += wxT('\r');
break; break;
case wxT('"'): case wxT('t'):
strResult += wxT('"'); strResult += wxT('\t');
break; 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
}
} }
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
}
}
return strResult; return strResult;
} }
// quote the string before writing it to file // quote the string before writing it to file