std::to_chars should now be supported by all compilers. The assert is
not needed because there are already tests for the extreme cases. It is
anyway bad style to have asserts in code under tests.
Change-Id: I5dbfa462168766e40fffa1f1780a167f1f37e72a
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Seems to work on my GCC but lets see if older GCC can handle it.
Change-Id: I2932798da3691201f7dd4c8c981ae0dc29d01a86
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
It is undefined behavior to access a uninitialized part of a union but
in this case it is not because both member have the same start member.
ControlBlock is in both at the address with the same layout and so it is
allowed by the C++ standard.
Change-Id: I3a165f67030d6726d2cb0cfbcbfb2622bcf7dcc4
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
An explicit operator for QLatin1StringView. That is dangerous if the
string is not ASCII and one for QUtf8StringView.
Change-Id: I2d0a0ca3854b47595563a19263aacd7f8825d026
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Both strings are not null terminated.
Change-Id: Ib9fb88925ef6ba261ae3c1ef69f0450935d31cc1
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Instead of creating a temporary string we simply call append directly.
Change-Id: I75ffd80a4359a19892b196f5d1ddb50b90c5a2cd
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
It used the size of the destination string but it had to use the size of
the appended string to inquire the maximum required size.
Change-Id: I1c910abab0ac60ed5fec1b3dc3a358e438532281
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
constData() was a workaround for the tests
Task-number: QDS-9847
Change-Id: I23fcca794ab50101ae70034079af46303c98c648
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Since we also license under GPL-3.0 WITH Qt-GPL-exception-1.0,
this applies only to a hypothetical newer version of GPL, that doesn't
exist yet. If such a version emerges, we can still decide to relicense...
While at it, replace (deprecated) GPL-3.0 with more explicit GPL-3.0-only
Change was done by running
find . -type f -exec perl -pi -e "s/LicenseRef-Qt-Commercial OR GPL-3.0\+ OR GPL-3.0 WITH Qt-GPL-exception-1.0/LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0/g" {} \;
Change-Id: I5097e6ce8d10233993ee30d7e25120e2659eb10b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Task-number: QTBUG-67283
Change-Id: I708fd1f9f2b73d60f57cc3568646929117825813
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
We expect mostly a string view which has no null termination. Code which
depends on null termination is broken and it is better break early.
Change-Id: I7c2c41fb114e6aaf3a23053b522b37f7af5e1abf
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Actually, the layout is the same, but we move the control block. To prevent
padding of the short string, we use pragma pack(1). To align the pointer
again, we add some dummy data with the size of a pointer minus a control
block because alignas is not working like expected on GCC.
Change-Id: Ide86ace243dab5f487da63492ebac018da45098a
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
There can be quite some copies with the swap method for the default case
that the string is inside the small string area. Instead now we minimize
copies of the smallstring area at the expense of more branches.
The swap approch needs no self tests and it uses the destructor to
remove allocated resources but it can copy three times more often. And
the destructor still has an additional branch in the copy case. Only in
the move case we can use the destructor of the other instance. This can
be surprising for some users which expect that the instance is empty
after a move(actually assuming that a instance is empty after a move is
undefined behavior).
Because SmallString is designed to hold the string in almost all cases
inside the small string area that case should be optimized.
Change-Id: I22cb62aa99b9713a221f103971f149c05e9ff6fa
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Using a value after the move is undefined. For example, if you move an
integer, it is not set to zero after the move. So you have to initialize
it again. Adding the take method to SmallString makes this explicit.
So if there is a case that you want to use the string again after
a move, use take or initialize it yourself.
Change-Id: I174116df9639d6a3f63c6f2c2a3bd184852927ce
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
GCC 12 was producing a huge warning log about this, thinking we were
overflowing the buffer. I don't see how.
In function ‘std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = char]’,
inlined from ‘void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = char*; _ForwardIterator2 = char*]’ at /usr/include/c++/12/bits/stl_algobase.h:182:11,
inlined from ‘void std::__reverse(_RandomAccessIterator, _RandomAccessIterator, random_access_iterator_tag) [with _RandomAccessIterator = char*]’ at /usr/include/c++/12/bits/stl_algo.h:1107:18,
inlined from ‘void std::reverse(_BIter, _BIter) [with _BIter = char*]’ at /usr/include/c++/12/bits/stl_algo.h:1134:21,
inlined from ‘static std::size_t Utils::BasicSmallString<Size>::itoa(long long int, char*, uint) [with unsigned int Size = 31]’ at smallstring.h:956:21,
[... many more frames ...]
move.h:205:11: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
smallstring.h:615:14: note: at offset 46 into destination object ‘buffer’ of size 22
615 | char buffer[22];
| ^~~~~~
smallstring.h:615:14: note: at offset [14, 22] into destination object ‘buffer’ of size 22
smallstring.h:615:14: note: at offset 46 into destination object ‘buffer’ of size 22
Change-Id: Iba16e8ea451b444ab213fffd16f491e608ee713a
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Skip the creation auf a QByteArray. Use QStringEncoder instead.
Change-Id: I3d2297b1fef27acb2136a64587c5af9099d92aa6
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
If you write
Utils::SmallStringView view;
Utils::SmallString text{view};
it selects the std::initializer_list contructor. Not the didicated
constructore. It is much to easy to get it wrong so it is better
to make it explicit.
Change-Id: I4240eaf1f39cf71d37df4480fea1ecfa3ea83cb0
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
There are still some methods missing but with C++20 we can maybe remove
SmallStringView.
Change-Id: I65a1eacda0a07cec824f1837e385faa01fc825e9
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Use more C++ api and constexpr. With C++ 17 we can use even more.
Change-Id: I33934cd7e087c311bf98501442df848bdb108279
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
If there is a newer file than the last indexing or if a file is added or
removed from the project or system PCH we have to reindex the project and
maybe the system PCH.
Change-Id: Ibce2a244190a79b5c422c469c065ddc11e44b2cb
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Failing test:
SymbolsCollector.CollectUsedMacrosWithoutExternalDefine
std::stable_partition can move-assigne object to itself
which was not properly handled in SmallString.
Change-Id: I719f3cb78cdace5fdbd9fcac3f5f099baa58a8c2
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
The small string control block moved to the beginning, so it is more cache
local. The control block is cleanup too, so it should be easier to read.
The alignment is removed because it is creating to big holes.
Change-Id: I401aeb9d55455cbaa5e722dd8192e54b525ddc40
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
If a class has a data method that returns a char pointer it can be
used to construct a SmallString and a SmallStringView.
Change-Id: I02dcba50babb3074b58998e5f907799e84361ed7
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Before the string was simply swapped with the other string which can lead
to an unexpected behavior for xvalues. Now the destructor of the source is
called and it is default initialized.
foo = std::move(bar);
bar would now hold the value of foo.
Change-Id: Ibea3f18333a168634b7faf2fdaf9b5b52c82d5cc
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
The database is using file path integer ids to handle file paths because
otherwise we would save many redundant data. This patch is improving it
further with the introduction of a database based file path cache. The
entries are now divided in a directory path and file name. This is quite
handy for directory based file watching.
Change-Id: I03f2e388e43f3d521d6bf8e39dfb95eb2309dc73
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
The reserve function is quite complicated because it is implementing a
grow pattern. Something we seldom need. So we now align to the next cache
line size.
Change-Id: I14bb88c12bd740a7afa7cd08969a4e07fb0f9add
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
We called reserve for even if we do not found anything to replace.
Change-Id: I01dfbb9e8152605c01fa007eb93586f9a30cf56e
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
You need to allocate the memory before you replace a smaller text with
a larger one. It has some overhead because you go two times over the text
but it is anyway not designed for a large text.
Change-Id: I2f56f1300a5daf9e26632b5b0667023a09ff4bd2
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>