Commit Graph

34 Commits

Author SHA1 Message Date
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
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
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
a15250051d Clang: Handle native file in the file cache
Different types are introduced for normalized and native file path. So the
compiler is warning you if you try the wrong format.

Change-Id: I1da0686b142cbf9bb7578468c2b50f90a94cebf9
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-11-23 11:55:15 +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
2fc4e17e31 Utils: Add Utils::SmallStringView::empty
It is required by many template function because it is used in the STL.

Change-Id: I5a2b9266d0c9d79bdc37cbbc4e7b62fac7a82b8b
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-09-21 12:35:24 +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
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
24e5dd0556 Utils: Add compare function for string views
It is more efficient to use compare instead of less and equal together.

Change-Id: I772b03ba02509c0ebc5d5d770be14cf7d5bd431e
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-28 13:46:38 +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
4c7cc99375 Utils: Fix short string capacity
The short string capacity is the data area size minus the size of \0.

Change-Id: Iffb4428bb81fc78bdc4c00218cf9f2c9ac8c25e5
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-04 09:47:59 +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
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
daa3aad651 Utils: Add startWith to string view
We will add more function if they are needed.

Change-Id: Iac6b432327be32a0778a82c23ed2de5996c555a1
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-01 12:40:28 +00:00
Marco Bubke
3b46c09520 Utils: Add isEmpty to string view
Change-Id: Ib7e77602dcdcdf481f6ab690bacef53c5dd92580
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-08-01 12:40:14 +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
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
c5d42503fa Utils: Add test that a longer path string is a short string
Change-Id: Ie4cf6ae5e2ac9fac878b3f85e88b1e64960a156d
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-02-01 09:19:51 +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
c072cdfb88 Clang: Add ClangPchManager
Compiling every header file again and again is quite time comsuming. There
are technics to improve this like preambles(a kind of automated
precompiled header) but they don't share their data between translation
units. This approach provides an automatically generated precompiled
header for every project and subproject to improve the loading time.

Change-Id: I34f5bd4db21951175920e2a9bbf6b97b1d705969
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-01-30 13:55:58 +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
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
Marco Bubke
47c01daeb2 UnitTest: Cleanup
Improve naming and introduce googletest.h.

Change-Id: I445c13db4c23d6dd5682ce0db3b83055cc6b8a89
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-09-19 15:17:54 +00:00