2c265d2700
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> |
||
---|---|---|
bin | ||
config.tests | ||
dist | ||
doc | ||
examples | ||
lib | ||
mkspecs | ||
qmake | ||
src | ||
tests | ||
util | ||
.gitattributes | ||
.gitignore | ||
.qmake.conf | ||
.tag | ||
config_help.txt | ||
configure | ||
configure.bat | ||
configure.json | ||
configure.pri | ||
header.BSD | ||
header.BSD-OLD | ||
header.COMM | ||
header.FDL | ||
header.FDL-OLD | ||
header.GPL | ||
header.GPL-EXCEPT | ||
header.LGPL | ||
header.LGPL3 | ||
header.LGPL3-COMM | ||
header.LGPL21 | ||
header.LGPL-NOGPL2 | ||
header.LGPL-ONLY | ||
INSTALL | ||
LGPL_EXCEPTION.txt | ||
LICENSE.FDL | ||
LICENSE.GPL2 | ||
LICENSE.GPL3 | ||
LICENSE.GPL3-EXCEPT | ||
LICENSE.GPLv3 | ||
LICENSE.LGPL3 | ||
LICENSE.LGPLv3 | ||
LICENSE.LGPLv21 | ||
LICENSE.PREVIEW.COMMERCIAL | ||
qtbase.pro | ||
sync.profile |