diff options
author | Anton Kudryavtsev <anton.kudryavtsev@corp.mail.ru> | 2018-01-30 19:57:28 +0300 |
---|---|---|
committer | Anton Kudryavtsev <antkudr@mail.ru> | 2018-02-02 11:08:11 +0000 |
commit | cdebc1a138eb4e4272b0b96e6bfce4fd66851ce1 (patch) | |
tree | 0b7d40584b3935955034e26dc5bd40f5ea228ca7 /src/corelib | |
parent | e8bf3a2ce7fcc153fbb9732b02b51167c5c4aaf5 (diff) |
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>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qstring.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 69751eb6dc..4e7baa18b6 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -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; } |