Commit Graph

102 Commits

Author SHA1 Message Date
Marco Bubke
0ad9b6fb3a Utils: Modernize SmallString
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>
2023-10-02 20:23:01 +00:00
Marco Bubke
85da9d7af5 Utils: Remove disabled warning
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>
2023-09-27 11:02:00 +00:00
Marco Bubke
a914b550ed Utils: Workaround warning about missing disabled warning
Change-Id: Icae1e30176fa5439a9e60be69b4eca754aca94d9
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
2023-09-27 11:01:51 +00:00
Marco Bubke
6c17805ddc Utils: Improve union layout
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>
2023-09-11 12:40:03 +00:00
Marco Bubke
a4f8cf709e Utils: Add more conversion operators to SmallString
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>
2023-09-07 14:56:53 +00:00
Marco Bubke
8c0402390c Utils: Add some more noexcepts
The code cannot throw any exceptions.

Change-Id: I735269e92458793df10f887b18a5d808070bac5b
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2023-08-24 08:54:36 +00:00
Marco Bubke
4c52e5ef95 Utils: remove a copy from the SmallString default constructor
StringDataLayout() is now constexpr too. Not that is useful because we
have to wait for constexpr new.

Change-Id: I34982c8b17e1935de5c65ec6fc1b01b572170966
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>
2023-08-24 08:54:18 +00:00
Marco Bubke
655ec9d948 Utils: Fix SmallString::contains
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>
2023-07-20 20:20:15 +00:00
Marco Bubke
0533636758 Utils: Skip one temporary string in constructor
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>
2023-07-20 15:06:43 +00:00
Marco Bubke
21983a8377 Utils: Fix SmallString::append(QStringView string)
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>
2023-07-20 10:30:25 +00:00
Tim Jenssen
1d183e4de7 QmlDesigner: use GTEST_INTERNAL_HAS_STRING_VIEW for str compare
constData() was a workaround for the tests

Task-number: QDS-9847
Change-Id: I23fcca794ab50101ae70034079af46303c98c648
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2023-05-08 15:29:16 +00:00
Kai Köhne
56baf8c058 Remove GPL-3.0+ from license identifiers
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>
2023-01-06 11:15:13 +00:00
Lucie Gérard
a7956df3ca Use SPDX license identifiers
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>
2022-08-26 12:27:18 +00:00
Marco Bubke
5a8d7c3d51 Utils: Remove code duplication in SmallString
It removes unwanted null termination too.

Change-Id: Iaea8699f7ccc387776b43e897fdd099764af2773
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2022-08-18 09:25:55 +00:00
Marco Bubke
c9d45d1bc0 Utils: Remove null termination from SmallString
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>
2022-08-16 16:15:51 +00:00
Marco Bubke
cf064500aa Utils: Improve memory layout code
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>
2022-08-16 16:15:45 +00:00
Marco Bubke
735346adb5 Utils: SmallString trades copies for branches
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>
2022-08-16 16:15:26 +00:00
Marco Bubke
8a0f7db8eb Utils: Make take of SmallString explicit
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>
2022-08-16 16:14:51 +00:00
Jarek Kobus
165fefffe8 Drop Qt5: Utils: Remove code below Qt 6.0.0
Change-Id: I6557238ceccc11c2d1fd8168f1e578fd27a1ee95
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
2022-07-25 07:12:50 +00:00
Tim Jenssen
c4e94c2c9c Merge remote-tracking branch 'origin/qmlprojectstorage'
Conflicts:
	src/plugins/qmldesigner/qmldesignerprojectmanager.cpp
	src/plugins/qmlprojectmanager/qmlproject.cpp
	src/plugins/qmlprojectmanager/qmlproject.h

Change-Id: I0c0d59c8e3b8455b6ac575d34fdf49f39388db7a
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2022-06-21 10:47:34 +00:00
Thiago Macieira
aa5d2eaf13 SmallString: Replace manual itoa implementation with std::to_chars
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>
2022-06-02 16:42:17 +00:00
Marco Bubke
6587feb3d8 Utils: Improve string conversion for Qt6
Skip the creation auf a QByteArray. Use QStringEncoder instead.

Change-Id: I3d2297b1fef27acb2136a64587c5af9099d92aa6
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2021-09-21 12:45:51 +00:00
Marco Bubke
8603eb5ba9 Utils: Remove std::initializer_list contructor
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>
2021-05-31 16:43:11 +00:00
Marco Bubke
611615f10b Utils: Rebase SmallStringView on std::string_view
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>
2021-03-24 14:12:12 +00:00
Marco Bubke
20690236d7 Utils: Add iterator constructors to small string
Change-Id: I34e15177268f0733200d25c90fd935485c3176ae
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2021-03-09 08:57:30 +00:00
Marco Bubke
0b3d03121f Utils: Modernize SmallString
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>
2020-05-27 13:09:03 +00:00
Marco Bubke
ae5ce649c1 Utils: SmallString swap cannot throw
Change-Id: I4ae30adc6ca77681a4b21281148831d3ab3d728e
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2020-05-27 13:08:46 +00:00
Marco Bubke
947cb9ed4e Clang: Improve file path cache
Change-Id: I940dc63c0fc95fbb826ed7d19a1ac1e4db5a542c
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2019-08-27 11:51:56 +00:00
Marco Bubke
56d611e0a3 ClangPchManager: Update PCHs if time stamps of dependencies changed
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>
2019-08-27 11:50:39 +00:00
Marco Bubke
f8aad27a88 Utils: Suppress warning in SmallString
Task-nubmer: QTCREATORBUG-20541
Change-Id: I7deb64f0f7c63c07641833408596ead0f4e087b8
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2019-01-14 13:02:29 +00:00
Marco Bubke
3d9974db95 Utils: Fix small string
Change-Id: I6a746eb28c6c803b9ade9f626a950cf93ba6fe99
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2018-09-03 14:26:05 +00:00
Orgad Shaneh
7cee991c70 Utils: Remove superfluous qualifications
Change-Id: I36e17dac0cff87f82f0ddaf97bc613389110f218
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-19 08:21:29 +00:00
Ivan Donchevskii
8ea31bb1e1 Utils: Fix unit-test failure caused by SmallString issue
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>
2018-05-24 09:44:39 +00:00
Marco Bubke
efd9b08eb4 Utils: Remove noexcept from SmallString::append
We want to get bad_alloc. ;-)

Change-Id: Icc7995405bfb96d3f709b80e30b13c5d81fb3979
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2018-04-04 13:36:51 +00:00
Marco Bubke
b6cb22899c Utils: Improve SmallString
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>
2018-04-04 13:34:20 +00:00
Marco Bubke
07fcd6f362 Utils: Simplify clone
Change-Id: I8b39696eee2ba8e19d827160bb80bd896491e69c
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2018-02-15 09:58:42 +00:00
Marco Bubke
2f8c075a01 Utils: Make default constructor of SmallString constexpr
Change-Id: Ibf381c9f18de878b1f67e28498cd28270e9220c7
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2018-02-01 14:47:57 +00:00
Marco Bubke
a572b2db6a Utils: Change SmallString::toView to SmallString::toStringView
This improves the readability of the code.

Change-Id: Ifccbaaa6003636848ea48e00d92abc44f5c2e0f1
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2018-01-22 13:22:00 +00:00
Marco Bubke
b3bed4c306 Utils: Introduce flexible constructor for SmallString and SmallStringView
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>
2018-01-22 13:21:52 +00:00
Marco Bubke
ce4d7e9d0e Utils: Fix smallstring move assignment
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>
2017-10-20 14:36:37 +00:00
Marco Bubke
d2e15e5f1e Clang: Add file cache
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>
2017-10-05 17:36:37 +00:00
Marco Bubke
fc231309e8 Utils: Fix reverse iterators in SmallString
Change-Id: I859c801fdb1ad68d5943b580f07a9e8260ae192a
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-09-21 12:35:10 +00:00
Marco Bubke
76a7dff82b Utils: Simplify SmallString reserve
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>
2017-09-18 10:17:11 +00:00
Robert Loehning
f4a8f52b0d Utils: Use ref instead of copying large object
Change-Id: I77ea6d1e9eaf16e92ce04cc59357b2c754d76e44
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2017-09-14 08:40:26 +00:00
Marco Bubke
8640ef1927 Utils: Convert to SmallStringView for comparison
Change-Id: I38d9716225b81091e8e75b26c9c2258a2aefa987
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-29 16:36:57 +00:00
Marco Bubke
381b51c012 Utils: Add toView to SmallString
Change-Id: I242a3a8e8411dfca19e50279928f97a5623e55d4
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-28 13:46:48 +00:00
Marco Bubke
d45cd9a35b Utils: Use C string functions
They are better optimized.

Change-Id: I6db1c94d283ee9f3f1555ce02b9b42d38003e2d0
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-28 13:46:28 +00:00
Marco Bubke
965379bc63 Utils: Don't touch the data if nothing is replace in SmallString
We called reserve for even if we do not found anything to replace.

Change-Id: I01dfbb9e8152605c01fa007eb93586f9a30cf56e
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2017-08-08 12:30:59 +00:00
Marco Bubke
4ae0c6782f Utils: Fix replace function in SmallString
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>
2017-08-04 10:33:03 +00:00
Marco Bubke
f6228cae22 Utils: Improve SmallString::operator<
Change-Id: I893634dd4e95b4103f0fc822e5268cc5f95d3d4b
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-04 09:55:48 +00:00