Go to file
Marc Mutz 2c265d2700 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>
2017-03-28 11:27:40 +00:00
bin don't try to timestamp injected qvulkanfunctions.h 2017-03-22 15:49:19 +00:00
config.tests Merge remote-tracking branch 'origin/5.9' into dev 2017-03-20 09:00:44 +01:00
dist Add changes file for 5.8.0 2017-01-02 06:50:47 +00:00
doc Merge remote-tracking branch 'origin/5.9' into dev 2017-03-20 09:00:44 +01:00
examples Merge remote-tracking branch 'origin/5.9' into dev 2017-03-28 09:28:31 +02:00
lib Purge all fonts 2015-08-18 19:59:14 +00:00
mkspecs Merge remote-tracking branch 'origin/5.9' into dev 2017-03-28 09:28:31 +02:00
qmake Merge remote-tracking branch 'origin/5.9' into dev 2017-03-28 09:28:31 +02:00
src QString: clean up internal string comparison functions 2017-03-28 11:27:40 +00:00
tests Merge remote-tracking branch 'origin/5.9' into dev 2017-03-28 09:28:31 +02:00
util Handle indirect sibling selector 2016-07-27 20:18:02 +00:00
.gitattributes Update the git-archive export options 2012-09-07 15:39:31 +02:00
.gitignore Overhaul .gitignore 2017-02-16 15:11:05 +00:00
.qmake.conf Bump version 2017-02-03 12:01:58 +00:00
.tag Update the git-archive export options 2012-09-07 15:39:31 +02:00
config_help.txt Merge remote-tracking branch 'origin/5.8' into 5.9 2017-02-24 20:01:42 +01:00
configure complain about various invalid configuration attempts 2017-01-06 20:10:10 +00:00
configure.bat reduce nesting in configure.bat 2017-01-10 12:44:21 +00:00
configure.json Merge remote-tracking branch 'origin/5.9' into dev 2017-03-02 09:04:38 +01:00
configure.pri Merge remote-tracking branch 'origin/5.8' into 5.9 2017-03-13 15:55:44 +01:00
header.BSD Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.BSD-OLD Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.COMM Add header template for commercial only modules 2015-10-19 10:37:18 +00:00
header.FDL Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.FDL-OLD Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.GPL Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.GPL-EXCEPT Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.LGPL Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.LGPL3 Update copyright headers 2015-02-11 06:49:51 +00:00
header.LGPL3-COMM Update copyright headers 2015-02-11 06:49:51 +00:00
header.LGPL21 Update copyright headers 2015-02-11 06:49:51 +00:00
header.LGPL-NOGPL2 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.LGPL-ONLY Update copyright headers 2015-02-11 06:49:51 +00:00
INSTALL Doc: Update links in INSTALL file 2015-02-16 09:06:41 +00:00
LGPL_EXCEPTION.txt Update copyright headers 2015-02-11 06:49:51 +00:00
LICENSE.FDL Initial import from the monolithic Qt. 2011-04-27 12:05:43 +02:00
LICENSE.GPL2 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.GPL3 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.GPL3-EXCEPT Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.GPLv3 Expand license scope from "Qt GUI Toolkit" to "Qt Toolkit" 2016-06-15 07:02:32 +00:00
LICENSE.LGPL3 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.LGPLv3 Expand license scope from "Qt GUI Toolkit" to "Qt Toolkit" 2016-06-15 07:02:32 +00:00
LICENSE.LGPLv21 Expand license scope from "Qt GUI Toolkit" to "Qt Toolkit" 2016-06-15 07:02:32 +00:00
LICENSE.PREVIEW.COMMERCIAL Add new license header templates and license files 2016-01-14 20:43:46 +00:00
qtbase.pro nuke configure -host-option 2016-12-13 18:55:59 +00:00
sync.profile don't try to timestamp injected qvulkanfunctions.h 2017-03-22 15:49:19 +00:00