QString: optimize remove()

In remove(const QString &str, Qt::CaseSensitivity cs)
call remove(QChar c, Qt::CaseSensitivity cs)
if str.size() is equal 1. It prevents quadratic behavior
for that case.

Change-Id: I9a7ab3019c580343533c8c6c6a04b6b0c8c1fb55
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Anton Kudryavtsev 2018-01-30 19:57:28 +03:00 committed by Anton Kudryavtsev
parent e8bf3a2ce7
commit cdebc1a138
1 changed files with 9 additions and 4 deletions

View File

@ -2599,10 +2599,15 @@ QString &QString::remove(int pos, int len)
*/
QString &QString::remove(const QString &str, Qt::CaseSensitivity cs)
{
if (str.d->size) {
int i = 0;
while ((i = indexOf(str, i, cs)) != -1)
remove(i, str.d->size);
const int strSize = str.size();
if (strSize) {
if (strSize == 1) {
remove(str.front(), cs);
} else {
int i = 0;
while ((i = indexOf(str, i, cs)) != -1)
remove(i, strSize);
}
}
return *this;
}