Commit Graph

102 Commits

Author SHA1 Message Date
Marco Bubke
d54db53d2f Utils: Fix spacing
Change-Id: I3c3f4e22ad64144f7ea92e671b9f582fd434b491
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-04 09:48:15 +00:00
Marco Bubke
08711525ec Utils: Clone the capacity too
It has it's advantages if the text grows otherwise we maybe waste memory.

Change-Id: Ic76d25207c2ef18182069fbf64bc0fb955a85353
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-04 09:40:09 +00:00
Marco Bubke
4cc89b97de Utils: Don't allocate new memory if it is fitting in the short string
If you call reserve on a read only reference we always allocated on the
heap which is not that smart.

Change-Id: Ib9653c6fc87bc65716a966545c13f7ecb3712039
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-04 09:32:21 +00:00
Marco Bubke
18453deafb Utils: Cleanup SmallString::replace
Improve the naming of the variables.

Change-Id: I125f3451e0e6a7437909067e9bff06cbeac111a0
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-04 09:22:04 +00:00
Marco Bubke
0e3dc045a1 Utils: Fix replace crash
The bug was that we returned the new end() but not the old reallocated
after a reallocation of the memory. The return value is used to move the
string after the found sub string to the next found sub string to the
new position of after the replaced sub string. Because the new end moved
more to the right we moved a much bigger chunk of memory. So we
accessed memory outside of the allocated memory.

Change-Id: I9ac276e201eabee896190da0cf0ee1d86860777d
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-04 09:05:33 +00:00
Marco Bubke
a279b55415 Utils: Fix missing initialization in SmallString
Change-Id: I9f8d7aee15c1908f89c6208390cc46d737789144
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-02 11:50:00 +00:00
Marco Bubke
1727e64349 Utils: Use string view instead of a string
This is preventing unneeded mallocs.

Change-Id: Ia1f9b1be90635e7aa8b4b6f6e6705e5671f946c5
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-01 12:40:33 +00:00
Marco Bubke
01e1f13bb9 Utils: Add + operator to SmallString
It should not be used for chained concatenation. Use initializer list
instead.

auto text = in + 'x';

auto text = Utils::SmallString{in, "x", other, ", "};

Change-Id: I453d986913eae89fd5e1f525b9f4e0c4bd089467
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-01 12:40:08 +00:00
Marco Bubke
1b14ec5056 Utils: Add number to string conversion
We use std::to_string except for integer where we want a low overhead
solution.

Change-Id: I16ce7d575d83ff56e61a5038aa7f9a1febfaf34f
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
2017-08-01 12:40:02 +00:00
Marco Bubke
48b17e341c Utils: Use replace instead of transform
Change-Id: I7399308b93280d1150a24e5729aefc60e1826ea6
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-07-19 11:24:54 +00:00
Marco Bubke
1a75db12f4 Clang: Improve speed by content generation
The argument parsing has some considerable overhead. We try to avoid that
with merging all content together in one file.

Change-Id: Icf426bb5d6a5569d59c180f94c7eab66a22a251c
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-02-16 17:39:05 +00:00
Marco Bubke
79e73ea4ee Fix spelling of unitttest_public
Change-Id: Id90dbfe30bb1f1c147299c4ac8cd210dbe7d8b82
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-02-03 15:35:44 +00:00
Marco Bubke
bdfb466cd2 Utils: Add replace for characters
It is much more performant to have a overload of char instead of providing
a string all the time.

Change-Id: I1a4ed82bf056f6af0c1f91c236b3fc30afa7f5d8
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-02-02 12:46:14 +00:00
Marco Bubke
a0c69c517c Utils: Fix long small string
We used only 6 bit to save the short size but for SmallString with a size
over 64 it is not enough. So we have now to use a uint16 instead of a
uint8 if the size if over 64.

Change-Id: I53558e492b6cb40b739b23a8af83d192a2e11bd2
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-01-31 16:12:18 +00:00
Marco Bubke
729c535376 Utils: Add intializer_list constructor in SmallString
You can now write

SmallString text = {"Oh ", women[4], " how much I miss you"};

if it can be casted to SmallStringView.

Change-Id: I86b69ee8d735017cac4391e7c4e68355eb5f227b
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-01-31 16:06:33 +00:00
Marco Bubke
9b4afa01a1 Utils: Improve and fix operators in SmallString
Change-Id: I51f4e647cbd3ada0c3a86d16f40fd8044acead33
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-01-31 16:06:28 +00:00
Marco Bubke
c02df443a2 Utils: Change SmallString::at from const reference to value
A char is smaller than a pointer.

Change-Id: Icc34b4cb3ccd4bad22e944d1e236d60f51086cfa
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-01-31 16:06:21 +00:00
Eike Ziller
63f66f28ac Use _t versions of various type traits
Available now after switching to C++14 and GCC>=4.9

Change-Id: I44e9859a6abe66db16d77b228466b65eadced8ae
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-01-30 10:46:22 +00:00
Robert Loehning
eeb0b8fd21 Revert "Revert "Utils: Remove old compiler support code""
Thomas provided a smaller fix.
This reverts commit 78fb7f44bf.

Change-Id: I1edff6477526fe4ce29df38852f47fe49117561e
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2017-01-19 12:21:43 +00:00
Alessandro Portale
78fb7f44bf Revert "Utils: Remove old compiler support code"
This reverts commit 8a32bcc5e7.

Broke build with MSVC 2015, update 3

Change-Id: Icb59b70fb00ea2a2ecc8d26c8177d21d82aaccf2
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2017-01-19 11:47:26 +00:00
Marco Bubke
8a32bcc5e7 Utils: Remove old compiler support code
We now support constexpr, noexcept and alignas on all compilers. Next will
be C++ 14 constexpr support.

Change-Id: I254049c60dcd82fc373ec907cbb5702a4b344978
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-01-19 10:59:40 +00:00
Marco Bubke
0011d81817 Utils: Activate copy constructor and assignment
The move only patter is quite powerful but has the drawback that some
STL algorithms get quite complicated. For short string or const references
should be not difference to a move. So we activate them for all cases.

Change-Id: I959c13796e69c45f31bb0ecbbe64a70d39961e3f
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-01-09 13:45:08 +00:00
Marco Bubke
023e1fa610 Utils: Add PathString to improve memory usage for longer paths
Change-Id: I90bca7eddfc4823406f1320a7f6e7836d53c3425
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-01-09 13:21:08 +00:00
Marco Bubke
7b6e671809 Utils: Change of less operator for SmallString
Comparing file paths can be quite expensive because the start very likely
with the same string. Sorting for size and only compare the string is less
expensive. For many algorithm we need a sort order, so making the less
operator cheaper is quite desirable.

Change-Id: I33e7abc7a65264e80376f445f8b6dcada0625ab9
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-01-09 13:20:40 +00:00
Marco Bubke
8088923f2f Utils: Add SmallStringView constructor to BasicSmallString
Change-Id: Ib8b92f9d39f342680f62433f8cc67d2adf1f6eb2
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-01-09 13:20:29 +00:00
Tim Jenssen
c191672013 Utils: Change UNIT_TEST_PUBLIC in unitttest_public
Change-Id: If60f24e3b055d543ba7864d4eb7e8287721d1012
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-01-09 13:20:17 +00:00
Marco Bubke
28a120b2e2 Utils: Workaround missing __cpp_noexcept in clang
Clang is not defining __cpp_noexcept.

Change-Id: Icb4e2dabb413e676614a9dd478e996d587c7f5d2
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2016-12-07 15:25:58 +00:00
Marco Bubke
b8e391e5f0 Utils: Fix SmallString reserve for read only references
The capacity of a real only reference is zero but the size is larger than
zero. So if we reserve memory the new capacity has to be bigger than the
size and the capacity.

Change-Id: I8b423da7e7c1cf7cee081d1b3f3464b6fb3f67cf
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2016-12-05 13:59:56 +00:00
Marco Bubke
b888520598 Utils: Reserve in smallstring was flaky
We have to copy the content of SmallString before we instantiate a new
constructor in the same memory. So the content to which data() is pointing
can be already invalid.

Change-Id: I3a0ab4f9ac0c1219c2bd75fc4412eaf56209ca64
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2016-11-30 15:32:48 +00:00
Marco Bubke
600b85defa Utils: Add carriage return strip method to SmallString
Sometimes you want to compare unix and windows texts in tests. This is a
convenient function to remove the carriage returns.

Change-Id: I164298b70d3d775dd45903ea3753ac0e68ed2fdc
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-11-28 16:48:25 +00:00
Marco Bubke
19a00f418f Utils: Add const reverse iterators to SmallString
Change-Id: Iefd9d6abafbe38dcb7d3ed9ea200ac3244902433
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-11-17 15:06:46 +00:00
Tim Jenssen
b31c3e0dcb Utils: Changeable SmallString stack size
The size of the small string optimization was hard coded. For some use
cases you want a bigger or smaller size. It is now configurable by a
template parameter. For that we changed the name to BasicSmallString and
added an alias of BasicSmallString<31> to SmallString.

Change-Id: I844b4420d260290307a6018bb6cc4cf3ba7bd449
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-11-01 16:17:21 +00:00
Marco Bubke
7cc348e048 Utils: Make SmallString(std::string) a template
Normal contructors are called before templated constructors. So it would
call SmallString(std::string("foo)) for SmallString("foo"). To prevent that
we change it to a template constructor.

Change-Id: Ibd249cedd638cbc2e6755c988be41fa5bb6e1ff6
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-11-01 15:34:11 +00:00
Marco Bubke
1cb16f98b0 Utils: Add += to SmallString
Actually it is a wrapper to append.

Change-Id: I61112a432423d0fcd3917aa28ea4cdc4842d51d4
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-11-01 12:56:27 +00:00
Marco Bubke
c56f3f235b Utils: Remove noexcept from SmallString constructor
Change-Id: I561b523bfac91098f721a5d53806670a3b682514
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-11-01 12:25:45 +00:00
Marco Bubke
092df2edaa Clang: Smallstring should not depend on std::ostream
We move the io operators in an extra header file because if we would
include ostream in smallstring.h we would blow the compile time.

Change-Id: Iea61ceedbbbcdd2adc6dc149794dab6e743084f8
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-08-08 15:01:53 +00:00
Marco Bubke
ebb82a2aa9 Clang: Remove undefined behavior
Never forward declare STL container.

Change-Id: Ie2d222f858f555294581bbea90300755973cb54e
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-08-08 13:50:57 +00:00
Marco Bubke
413a601f69 Clang: Prevent endless recursion
SmallString has a char * constructor.

Change-Id: If48f42c4ef667bda921f9c81fd755af037f6f3cf
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-08-08 13:50:48 +00:00
Orgad Shaneh
1853f01a5b Merge remote-tracking branch 'origin/4.1'
Change-Id: Ia442f30f387fe9292217582260bbe79e54608810
2016-08-05 11:40:07 +02:00
Orgad Shaneh
b041c6c8d9 Utils: Add a missing include in small string
Change-Id: I95717e170bfba3f4a1f089536676b73ba40b1df4
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2016-08-04 17:00:50 +00:00
Marco Bubke
4d29ca2d3a Utils: Add clone functions to small string
Change-Id: I4e1ff40437253ce9fa047b476edb5d69654963b2
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-08-02 13:38:32 +00:00
Marco Bubke
95ace75cc4 Utils: Add QDataStream operator to small string
Change-Id: If46e8933b484d6780505dd57e45596e44fccc83c
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-08-02 13:38:27 +00:00
Marco Bubke
0549c6af97 Utils: Add std::string conversion constructor and operator to small string
Change-Id: Ia76d7647fc8d2c9b72bc5bce2e7a6e2c3fcc18cc
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-08-02 13:38:23 +00:00
Marco Bubke
390e2d164c Utils: Add iterator constructors to small string
Change-Id: Ib8fcacd5dc520842cf5cee73ea21c021221158ca
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-08-02 13:38:19 +00:00
Marco Bubke
7610e48716 Utils: Fix smallstring
Change-Id: I681df8c3fd9aa84f14d5d581633894605f56b71a
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-08-02 13:38:14 +00:00
Marco Bubke
7d342471a4 SmallString: Fix ambiguity of iterators
std::size_t is a undefined unsigned integer type and std::ptrdiff_t is a
undefined signed integer type. So sometimes the compiler doesn't know
which to choose because both could represent a integer.

Change-Id: I669cd44c6f16854dfe3f3cc44edbfc422e1cbd6a
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
2016-06-23 14:08:43 +00:00
Marco Bubke
b2c8d76156 Utils: Add constructor for character pointer
Change-Id: I12bd787caf911502a666de2c324bb74b8bd7b0aa
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
2016-03-08 11:50:30 +00:00
Marco Bubke
640d126917 Utils: Optimize Small String comparison a little bit
Change-Id: I798d4c399b1aced566e9b302463fd6491c04e8a1
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
2016-02-25 17:29:46 +00:00
Marco Bubke
fc4af46bca Utils: Remove operator[]
Because the operator is always accessing data which has a branch is can be
much slower than iterators. SmallString is optimized for performance so
it would be quite misleading to have a non performing access operator.

Change-Id: Id882c3c12508afa393ce0766bbb680690a193c95
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
2016-02-25 09:40:05 +00:00
Marco Bubke
6315bd5de2 Utils: Rename hasAllocated in isReference
HasAllocated it misleading because it means that it has read only
references too. Maybe isPointing would be good too but so it is more
orthogonal to isReadOnlyReference.

Change-Id: I79aaa271aa302de2500c2ea81614e433d76f74ec
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
2016-02-25 09:39:57 +00:00