optimize Replace() to use a linear algorithm (closes #9135)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59420 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-03-07 16:07:58 +00:00
parent 101b242093
commit 072682ce44
4 changed files with 70 additions and 20 deletions

View File

@@ -281,6 +281,18 @@ BENCHMARK_FUNC(ReplaceAll)
return str.Replace("x", "y") != 0;
}
BENCHMARK_FUNC(ReplaceLonger)
{
wxString str('x', ASCIISTR_LEN);
return str.Replace("x", "yy") != 0;
}
BENCHMARK_FUNC(ReplaceShorter)
{
wxString str('x', ASCIISTR_LEN);
return str.Replace("xx", "y") != 0;
}
// ----------------------------------------------------------------------------
// string buffers: wx[W]CharBuffer

View File

@@ -318,7 +318,7 @@ void StringTestCase::Replace()
{ \
wxString s(o,olen); \
s.replace( pos , len , replacement ); \
CPPUNIT_ASSERT( s == wxString(r,rlen) ); \
CPPUNIT_ASSERT_EQUAL( wxString(r,rlen), s ); \
}
TEST_NULLCHARREPLACE( _T("null\0char"), 9, 5, 1, _T("d"),
@@ -328,7 +328,7 @@ void StringTestCase::Replace()
{ \
wxString s(o,olen); \
s.Replace( olds, news, all ); \
CPPUNIT_ASSERT( s == wxString(r,rlen) ); \
CPPUNIT_ASSERT_EQUAL( wxString(r,rlen), s ); \
}
TEST_WXREPLACE( _T("null\0char"), 9, _T("c"), _T("de"), true,
@@ -338,6 +338,10 @@ void StringTestCase::Replace()
_T("null\0char"), 9 );
TEST_WXREPLACE( "life", 4, "f", "", false, "lie", 3 );
TEST_WXREPLACE( "life", 4, "f", "", true, "lie", 3 );
TEST_WXREPLACE( "life", 4, "fe", "ve", true, "live", 4 );
TEST_WXREPLACE( "xx", 2, "x", "yy", true, "yyyy", 4 );
TEST_WXREPLACE( "xxx", 3, "xx", "z", true, "zx", 2 );
#undef TEST_WXREPLACE
#undef TEST_NULLCHARREPLACE