Try and reduce memory allocs when (un)escaping strings
This commit is contained in:
parent
e4b56ab7f1
commit
ca5049b6bc
|
@ -142,6 +142,8 @@ wxString EscapeString( const wxString& aSource, ESCAPE_CONTEXT aContext )
|
||||||
{
|
{
|
||||||
wxString converted;
|
wxString converted;
|
||||||
|
|
||||||
|
converted.reserve( aSource.length() );
|
||||||
|
|
||||||
for( wxUniChar c: aSource )
|
for( wxUniChar c: aSource )
|
||||||
{
|
{
|
||||||
if( aContext == CTX_NETNAME )
|
if( aContext == CTX_NETNAME )
|
||||||
|
@ -243,9 +245,17 @@ wxString EscapeString( const wxString& aSource, ESCAPE_CONTEXT aContext )
|
||||||
|
|
||||||
wxString UnescapeString( const wxString& aSource )
|
wxString UnescapeString( const wxString& aSource )
|
||||||
{
|
{
|
||||||
wxString newbuf;
|
|
||||||
size_t sourceLen = aSource.length();
|
size_t sourceLen = aSource.length();
|
||||||
|
|
||||||
|
// smallest escape string is three characters, shortcut everything else
|
||||||
|
if( sourceLen <= 2 )
|
||||||
|
{
|
||||||
|
return aSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString newbuf;
|
||||||
|
newbuf.reserve( sourceLen );
|
||||||
|
|
||||||
for( size_t i = 0; i < sourceLen; ++i )
|
for( size_t i = 0; i < sourceLen; ++i )
|
||||||
{
|
{
|
||||||
wxUniChar ch = aSource[i];
|
wxUniChar ch = aSource[i];
|
||||||
|
|
Loading…
Reference in New Issue