summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qstringalgorithms_p.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-05-03 19:52:56 +0200
committerMarc Mutz <marc.mutz@kdab.com>2017-05-04 07:20:55 +0000
commitb1debc11c118bb1e49a9e92a77194140255854fc (patch)
tree5a367d77e155170d6b4b269a35559d80b5495715 /src/corelib/tools/qstringalgorithms_p.h
parentb53f8bf040670f78d4e85de0c80f61cea23952c4 (diff)
QStringAlgorithms/private: prefer to trim whitespace from the end
When calculating what to trim in trimmed_helper_positions(), first trim the end, then the front. This way, a string that consists of just whitespace will remain anchored at its front, and we do not run into the memmove case in trimmed_helper_inplace, which, even though there's zero elements to move, still calls a potentially-out-of-line function (memmove()). Change-Id: I7024ffa1f7ae2effb9c5166ec8f30a42b8d51079 Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools/qstringalgorithms_p.h')
-rw-r--r--src/corelib/tools/qstringalgorithms_p.h8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/corelib/tools/qstringalgorithms_p.h b/src/corelib/tools/qstringalgorithms_p.h
index c5470bc7ad..4bcf697f78 100644
--- a/src/corelib/tools/qstringalgorithms_p.h
+++ b/src/corelib/tools/qstringalgorithms_p.h
@@ -89,14 +89,12 @@ template <typename StringType> struct QStringAlgorithms
static inline void trimmed_helper_positions(const Char *&begin, const Char *&end)
{
+ // skip white space from end
+ while (begin < end && isSpace(end[-1]))
+ --end;
// skip white space from start
while (begin < end && isSpace(*begin))
begin++;
- // skip white space from end
- if (begin < end) {
- while (begin < end && isSpace(end[-1]))
- end--;
- }
}
static inline StringType trimmed_helper(StringType &str)