diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-03-08 08:43:54 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-03-28 11:27:40 +0000 |
commit | 2c265d270016a75dc8a77cb34ef5e294a36ee703 (patch) | |
tree | e88eb9a32ceff7e82406408b06bfcf5eb95dbdbf /src/corelib/tools/qstringview.cpp | |
parent | 71a2d4fa3d9e1293b436957fd615908e685153eb (diff) |
QString: clean up internal string comparison functions
String comparison drew on a large number of internal functions such as
qMemEquals, ucstr{n,}{i,}cmp, and QString::compare_helper, all with
wildly different calling conventions. E.g. ucstrncmp took its
arguments as QChar*, while ucstricmp required ushort*. A complete
cleanup of these functions is left for another patch. This patch, as a
first step, centralizes calls to these functions.
Introduce two helpers, qt_compare_strings(QStringView, QStringView, cs)
and qt_compare_strings(QStringView, QLatin1String, cs) and replace all
uses of said lower-level functions with calls to these two functions.
I'm using QStringView instead of the more traditional (QChar*,int)
pairs, since we get two major benefits:
1. The onus of checking for valid arguments is put on the callers
(creating QStringViews with negative sizes is UB), allowing these
functions to be noexcept, even though the implementation still
calls functions taking (ptr, size) or (ptr, ptr) tuples. Duly add a
few asserts where we construct QStringViews from (ptr, size) pairs
passed in through exported API.
2. Since QStringView can be constructed from both ushort* and QChar*,
we no longer have to cast at the call sites. Much of the
simplification of the code is due to reduced casts.
The Windows 64-bit ABI stipulates that no values greater than the
register width can be passed in registers (no register pairing as with
all other ABIs), but a) that is their problem, b) it does not seem to
matter within a TU, c) MS is known to introduce new calling
conventions all the time (like __vectorcall in MSVC2013), so maybe
they will introduce a __faststructcall at some point and d) giving up
on the above-mentioned two benefits for an unknown runtime cost means
we're falling prey to premature optimization.
As a consequence of the cleanup, qMemEquals() and ucstrnicmp(ushort*,
ushort*, int) can already be removed.
Port the ucstr{i,}cmp() functions to QChar/char to avoid casting in
their only callers, qt_compare_strings().
Port ucstrcmp from int to size_t indices to avoid MSVC warnings when
passing QStringView::size() to them.
Change-Id: I4a8add0fc773dc0e1225a3b9a1c1248341a1720f
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/tools/qstringview.cpp')
0 files changed, 0 insertions, 0 deletions