Commit Graph

13 Commits

Author SHA1 Message Date
Friedemann Kleint
019dd88d2c QStringView: Add compare() member function
There was no public API for doing case-insensitive comparisons
of QStringView.

Task-number: QTBUG-69389
Change-Id: I1b021eefec35e135b97fb87704c8dc137232d83d
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2018-07-13 13:32:34 +00:00
Jani Heikkinen
a6514ddd33 Fix license headers
Remove usage of outdated header.LGPL21 and replace those with proper
one (header.LGPL in src, header.GPL-EXCEPT in tests)

Change-Id: Ia4d1c0d84b77f09787fe7c30670747a1fe2aff29
Reviewed-by: Liang Qi <liang.qi@qt.io>
2018-01-11 11:40:36 +00:00
Simon Hausmann
984ad61249 Improve readability of code that uses the Qt signed size type
During the container BoF session at the Qt Contributor Summit 2017 the
name of the signed size type became a subject of discussion in the
context of readability of code using this type and the intention of
using it for all length, size and count properties throughout the entire
framework in future versions of Qt.

This change proposes qsizetype as new name for qssize_t to emphasize the
readability of code over POSIX compatibility, the former being
potentially more relevant than the latter to the majority of users of
Qt.

Change-Id: Idb99cb4a8782703c054fa463a9e5af23a918e7f3
Reviewed-by: Samuel Gaist <samuel.gaist@edeltech.ch>
Reviewed-by: David Faure <david.faure@kdab.com>
2017-11-28 18:41:40 +00:00
Thiago Macieira
f7350ac99e Improve qustrlen further by avoiding the alignment prologue
This avoids looping prior to the main 16-byte loop, by performing one
load that may include bytes prior to the start of the string. This is
guaranteed not to fault, since str points to a valid character, but it
may cause Valgrind to print warnings.

Change-Id: I6e9274c1e7444ad48c81fffd14dcae854bba24b2
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2017-09-26 18:19:35 +00:00
Thiago Macieira
3b61cd6ad7 QStringView: De-inline the length calculation so we can use SSE2
Performance is more important in this case than the theoretical benefit
of constexpr. This commit implements the SSE2 search for 16-bit null and
it might be possible to implement the equivalent for AArch64
(investigation required). It also adds a fallback to wcslen() for
systems where wchar_t is short (non-x86 Windows or 32-bit x86 build with
-no-sse2).

We can re-add the constexpr loop once the C++ language has a way of
overloading constexpr and non-constexpr. GCC has a non-standard way to
do that with __builtin_constant_p, which is also implemented in this
commit, but note that the inline function is still not constexpr.

Change-Id: I6e9274c1e7444ad48c81fffd14dcaacafda5ebdc
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2017-09-13 16:19:45 +00:00
Marc Mutz
3c592a17f1 QStringView: add constructor from pointer pair
This is often more natural than (ptr, len), and I need it in the
implementation of QStringView::trimmed().

Change-Id: I1d99b5ddaf76eee0582150b0233ef6ce9c37d25d
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2017-05-16 09:34:50 +00:00
Marc Mutz
09f6227653 QtTest: add support for printing QStringViews
[ChangeLog][QtTest][QCOMPARE] Now supports printing QStringViews in
case of test failures.

Change-Id: I4dc2542cd1013fd63c094c249e721d7102387bde
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2017-04-24 19:35:11 +00:00
Marc Mutz
5311eb0d8e Use new Q_STDLIB_UNICODE_STRINGS and Q_COMPILER_UNICODE_STRINGS
... instead of the combination with Q_OS_WIN we used so far.

This patch adapts ocurrences that are new in 5.10.

Change-Id: If392df481713e56c776c2326e0e02324a3a80c89
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2017-04-20 18:10:59 +00:00
Marc Mutz
be49235266 QStringView: use qssize_t as size_type
Nothing changes, we've just given 'QIntegerForSizeof<size_t>::Signed'
a better name in qglobal.h and now use it in QStringView API and
users.

Change-Id: Ibea1ae26e95b3a96708400fd4b0cd120459d57b6
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2017-04-06 02:38:25 +00:00
Marc Mutz
8b5aa7b6c4 QStringView: add an array ctor
With sufficient enable_if magic, the array ctor can overload the
pointer ctor and statically determine the size of the array passed.
Consequently, remove the sizeof in QStringViewLiteral again.

Change-Id: I486baa3cafefde60ccc5f2b47eb94ee53cefe63c
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2017-04-04 11:33:08 +00:00
Marc Mutz
54dd87ca0f QStringView: add tests for relational operators
Remove most of the std::equal() tests that were used to determine
equality in pre-relational-operator-times again.

Amends a1421e4787.

Change-Id: Iff64808f5ac60861caee899d594b512b58046636
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2017-03-31 11:23:11 +00:00
Marc Mutz
7180236063 QStringView: improve manual overload management
We want to prevent

  QStringView(QChar|QLatin1String|QByteArray|const char*)

from compiling as QStringView(QString(...)), so I added = delete'ed
ctors for these types to QStringView. However, that makes QStringView
participate in overload resolution for these types. Even if the
QStringView ctor will always fail to compile, the presence of these
ctors alone makes calls to functions overloaded on QString and
QStringView ambiguous:

   f(QStringView);
   f(QString);
   f(foo);        // ambiguous
   f(QChar('f'))    // ambiguous
   f(QLatin1String(foo)); // ambiguous
   f(QByteArray(foo));    // ambiguous

Fix by making the QString and QStringRef constructors templates
constrained to accept only these two types. This should also help to
move the QStringView definition to before the QString one (as soon as
we get rid of or start to ignore QString::Null), simplifying a lot of
code in qstring.h down the line.

This should also fix MSVC's accepting of two user-defined conversions
which caused static non-compile-tests to fail in the initial
QStringView patch, and which were therefore removed. This patch brings
them back.

Change-Id: I95ac38c0d31cd8c726f7e952017569d32e484413
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-03-29 12:29:35 +00:00
Marc Mutz
00a8be85d1 Long live QStringView!
QStringView is a simple container for (const QChar*, int) and (const
char16_t*, size_t). It acts as a replacement interface type for const
QString and const QStringRef, and enables passing all kinds of
string-like types to functions otherwise expecting const QString& -
without the need to convert to QString first.

The use of this new class is guarded by a macro that enables three
levels of QStringView support:

 1. offer QStringView, overload some functions taking QString with
    QStringView

 2. like 1, but remove all overloads of functions taking QStringRef,
    leaving only the function taking QStringView.  Do this only where
    QStringRef overloads tradionally existed.

 3. like 2, but replace functions taking QString, too.

This is done in order to measure the impact of QStringView on code
size and execution speed, and to help guide the decision of which
level to choose for Qt 6.

This first patch adds QStringView with most of its planned
constructors, but not much more than iterators and isNull()/isEmpty().

Further patches will add support for QStringView to QStringBuilder,
add QStringView overloads of functions taking QString, and add the
complete API of const QString to QStringView.

[ChangeLog][QtCore][QStringView] New class, superseding const QString
and QStringRef as function parameters, accepting a wide variety of
UTF-16 string data sources, e.g. u"string", std::u16string{,_view},
and, on Windows, L"string", std::wstring{,_view} without converting to
QString first.

Change-Id: Iac273e46b2c61ec2c31b3dacebb29500599d6898
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2017-03-24 18:34:35 +00:00