The code here performs a std::mismatch() on the normalized parts of
'root' and 'path', returning whether 'path' is a prefix of 'root'. If
'path' is a proper prefix of 'root', returns the first 'root' part
after 'path', in '*match'.
Instead of using QString::splitRef(), perform the splitting as we go,
using this class' own tool, QStringSplitter.
The goal here is to avoid the heap allocation caused by the QVector
return of splitRef(), of course. But even though using QStringSplitter
means the splitting is now purely inline, text size in optimized GCC 7
Linux AMD64 builds increases by only 24B.
Change-Id: I396cc6a30306940220c9e783c31506e6ac17b784
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
TLD lookup is performed in up to three steps, which are decribed in a
code comment. For the purposes of this patch, it suffices to mention
that the last two steps involved a QStringBuilder expression.
Avoid having to build these strings by distinguishing between the
lookups using an enum instead of a string prefix. Since qt_hash()
calls can now be chained, form the hash value by hashing the prefix
character and the domain (part) separately.
Also perform the expensive fromUtf8() call only when the string prefix
(if any) matched. Once we have nothrow UTF-8/UTF-16 comparison
operators, qIsEffectiveTLD() will no longer allocate memory, and run
at full speed. Not there, yet, though.
I have full confidence that the optimizer will have field day with
this, inline all three containsTLDEntry() calls, and constant-fold the
checks inside the loop. GCC does, so I didn't try to do it by hand.
Change-Id: I1a7647ff52b6742310928ad859d851d1f0c6bdc3
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
There are some callers of qt_hash that first build a string just to hash it.
By allowing to pass an initial value for 'h', we can chain qt_hash() calls
to avoid having to allocate memory just to hash a two-part string.
Change-Id: Ifaca82d47b2fb8c707912342c3ddd84f91e70267
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Saves 240B in QtCore text size on optimized GCC 7 Linux AMD64 builds.
Change-Id: Ifa7b8735027575fbe381896dce608b80ec458ee9
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
This is not the complete set, since we don't yet have qCompareStrings()
for UTF-8 strings, but relational operators are so important that we
need _something_ before we have _everything_.
Change-Id: I213b741e5b91f09aa1f0c6c21f64d764fceb27a1
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
These symbols should at least be mentioned in the documentation.
Also comment on the option of using template variables for them once
we haev support for C++14
Change-Id: Ia40f9b89d9d8a38536a2e51ae3f174b8f16ca7d6
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This ports all to<Integer>() functions in QLocale to QStringView.
Change-Id: Idc3f026d5afdf51abab670b54ea96d2361cdc350
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
... leveraging the existing support for QLatin1String, which is the
char equivalent of QStringView.
The only noteworthy changes here are the port of the low-level
functions to size_t and that the internal template function,
setColorFromString(), can now take its argument by value, since only
views are ever passed to it anymore.
In the test, used new QTest::addRow() to format test names, and
introduced temporaries to avoid re-calculating the same input values
for every check.
Change-Id: Ia3c59e5c435ff753f34993a8d85c0c0b4e8e2b22
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
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>
It replaces Posix' ssize_t in cross-platform code. Most importantly,
it allows QStringView users to refer to QStringView::size_type by
a shorter, less intimidating name.
Change-Id: I2128fefd2ffdd258b0b55cd90802a23c6bc033f6
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
These free functions are designed to solve the problem that we
currently have QString::compare(QString, QString), but we have no
QString::compare(QStringRef, QString), even though we have
QString::compare(QStringRef). A compare(QString, QStringRef) only
exists in QStringRef.
This makes writing generic code tedious and error prone.
Notably absent are comparisons involving char* and QByteArray. These
will be added when we add QUtf8String, the UTF-8 counterpart to
QLatin1String.
Change-Id: I2dd7c4b1a1e0883ef0091396ee8c190012f4efba
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This ports all functions in qlocale_p.h to QStringView that can be
ported with the QStringView features we already have.
Prerequisite for QStringView::to<Integer>(), and
QLocale::to<Integer>(QStringView).
Change-Id: I52112dc199cdf3a8545e722399b1c9cceaf797e1
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
The class does not need to be exported, as it is all-inline, and
non-polymorphic.
The class also does not need a default ctor, except that QVector
requires it, so make the default ctor private and grant QVector
friendship.
Add constexpr and noexcept.
Mark as primitive instead of movable.
Change-Id: Ia5d11de8eb993cb080002804e11176dc5226a04c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
The parse() method's so-called "currentValue" is a caller-supplied
const that isn't (because it can't be) updated to reflect what's
parsed, albeit parse() passes it to other methods that presume it is
(I'll fix this in a later commit). Renamed to reflect that it
actually just supplies defaults for any fields not parsed from the
string. Then newCurrentValue is in fact the date-time we finally end
up having parsed, so rename it to reflect that.
Change-Id: Ic6add2673b5b245606dbb6415d84c18fc085e456
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Make some variables more local.
Make a loop simpler (and run it earlier).
Change-Id: I28c0c933b2a6599973d70d66105da6046189d8eb
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
With iOS 10 you can, with some versions of iPad/iPhone (e.g
iPad pro), start a trackpad gesture by using two finger swipe
on the input panel. This will let you move the cursor around
in the text edit.
This patch will implement the missing function that makes this
available also on Qt/iOS.
[ChangeLog][iOS] Support added for using the input panel as
a trackpad using two-finger swipe.
Task-number: QTBUG-59403
Change-Id: I456f5841e10d1e04218aafc78db87671f1a39ca9
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
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>
Add new enum QPrinter::PdfVersion to switch QPdfWriter
into PDF/A-1b mode. In that mode
- meta data are embedded in XMP format
- a color profile for sRGB is embedded and an OutputIntent defined
- the ID key is added to the document trailer dictionary
- a CIDSet entry is added to the font descriptor
- transparency is removed from pens, brushes and images
Change-Id: Ia8a24d83609b239e716aefc1ba05f07320dbd290
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Consider this pseudo code:
setSystemClip(region);
setSystemTransform( scale 2x );
setSystemTransform( scale 2x );
The second call to setSystemTransform should be a noop. Yet, with
the current code in setSystemTransform, the region would be scaled
twice by 2x and thus the clipping would be incorrect.
Fix that by saving the original untransformed clip and in
setSystemTransform recalculate the effective transform.
This is also a better fix for QTBUG-44067 /
sha: 083a945c166b325298a43ba591b1338d1b0f99b6, since with this patch
the order in which system clip, viewport and transform are set does
no longer matter.
Task-number: QTBUG-57257
Task-number: QTBUG-55698
Change-Id: Ibc232822e97ab116f7173a0cc50bba5a367619d8
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This temporary workaround allows to compile with GHS toolchain and
should be removed when GHS provides patch to fix the compiler issue.
Change-Id: I0d0eac8054e6ba2f448fed3d3c80a518e0d2af97
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
If the keyboard is hidden via the hide keyboard button then the edit
menu should also hide with it. This ensures it behaves in the same way
as native applications on iOS then.
Change-Id: I4c714dd5c5cb27d8eaf310e2911dc38feb1cb74e
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
After applying the correction matrix the front face is CW, not CCW.
The examples work either way but fix them up to avoid reader confusion.
Change-Id: I491e6dc17c21897a59f36d32061e937f2b6c4c9d
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
In a multi-threaded setup it is not unlikely that
releaseSwapChainResources() will wait for and submit any remaining
frame building. Hence a wait is necessary also after invoking the user's
implementation.
Change-Id: I3c963c05c1c3981980da5e4ff9c572df24a1e473
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
... and remove now-superfluous overloads.
Adapt the sole user of the (QChar*, int) overload to construct a
QStringView first, which removes the ugly cast at the call site.
Change-Id: Ie5249d4b1b82d471896548e8a7d83c130ae28130
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
The returned data is in US-ASCII (or else Latin-1), and resides in
consecutive memory. We can therefore return it in a QLatin1String,
which, however, will in general not be NUL-terminated.
Many users use the return value as part of a QStringBuilder
expression, and those which are not are not pessimized further by
this change.
The caller in qtimezoneprivate_icu looks as if it could simply zero
-terminate the return value and use it as-is, as opposed to
converting to UTF-8, but I left the code equivalent to the original
just the same.
Change-Id: I0e628af8c1320fcff8d0aacf160e859681d2b85a
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Set the limit to 128 instead of the default 64 by adding
QMAKE_CXXFLAGS += --pending_instantiations=128. This is
needed by QMetaType::typeName array implementation.
Change-Id: I3fd13967f862f492210572cfe7ee9ffc5e7c9745
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Ensures that numbers representable as 64-bit integer
are not printed using exponent notation.
Some JSON implementations such as the one of the Go
standard library expect this in the default
conversion to int.
Change-Id: Ic3ac718b7fd36462b4fcabbfb100a528a87798c8
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
... as used in qstring.cpp, too. QChar is only marked as movable, not
primitive, as it should have been and ushort is, and there's some hope
that the template instantiations can be shared across TUs.
Saves a rather disappointing 148B in text size on optimized GCC 7
Linux AMD64 builds.
Change-Id: Ic9558a4d83611a6461cd5540c9090cbd4c4f2f4e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This fixes a warning-turned-Werror in qdistancefield.cpp:
In member function ‘void QVarLengthArray<T, Prealloc>::realloc(int, int) [with T = bool; int Prealloc = 256]’,
inlined from ‘void makeDistanceField(QDistanceFieldData*, const QPainterPath&, int, int)’ at ../../include/QtCore/../../../../qt5/qtbase/src/corelib/tools/qvarlengtharray.h:275:10:
../../include/QtCore/../../../../qt5/qtbase/src/corelib/tools/qvarlengtharray.h:390:19: error: ‘void* memcpy(void*, const void*, size_t)’: specified size between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
memcpy(ptr, oldPtr, copySize * sizeof(T));
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Apparently GCC cannot rule out that copySize may be negative in the
call to memcpy. Put GCC on the right track by adding a Q_ASSUME.
Change-Id: I63e3801e52ebe2a7f77e3a97ef03ec3869319c8c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
By default SQLite opens DB in Serialized mode, allowing connections to be used
from several threads simultaneously: https://www.sqlite.org/threadsafe.html
According to Qt documentation, database can only be used from one thread.
This change opens sqlite dabases in "Multi-thread" mode, so that one does not
pay for useless mutex locking for each DB access
Change-Id: Ife61f1a648d74c91d3b27a2ce0059d052ccc62b2
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-Werror is now disabled for that compiler, but it doesn't hurt to fix.
io/qstandardpaths_unix.cpp:149:32: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
qtestcase.cpp:2330:31: error: narrowing conversion of '(ms / 1000)' from 'int' to '_Timet {aka unsigned int}' inside { } [-Werror=narrowing]
Change-Id: Id92f4a61915b49ddaee6fffd14aea2c1e686e8f2
Reviewed-by: Samuli Piippo <samuli.piippo@qt.io>
The compiler is mostly GCC in disguise, but the libraries are not. Since
the toolchain is not open, it's difficult to fix issues in it.
Task-number: QTBUG-59671
Task-number: QTBUG-59672
Change-Id: Id92f4a61915b49ddaee6fffd14aea2639153f073
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
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>
Fix the condition in QWidgetPrivate::resolveLocale() to decide whether
to propagate locale: make it match setLocale_helper()'s condition when
deciding whether to propagate to descendants. This lead to a
QDateTimeEdit's calendar popup not getting told what locale to use
correctly, unless we setLocale() on it overtly, which then blocked
propagation of locale changes to it unless QDateTimeEdit manually
propagated the changes.
Fix the documentation of WA_WindowPropagation to mention locale as
also being propagated (which it was in several places, only neglecting
this one in resolveLocale).
[ChangeLog][QWidget][Qt::WA_WindowPropagation] Propagate locale
consistently, along with font and palette, within the widget
hierarchy. Previously, locale was propagated on ancestral
setLocale(), but not on creation of the descendant.
Task-number: QTBUG-59106
Change-Id: I92270f7789c8eda66a458274a658c84c7b0df754
Reviewed-by: David Faure <david.faure@kdab.com>
Happens on non-Linux, non-macOS Unix systems (got it on FreeBSD).
Change-Id: Ie67d35dff21147e99ad9fffd14acc7308b5ff17e
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>