Commit Graph

74 Commits

Author SHA1 Message Date
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
Marco Bubke
e562af2c29 Utils: Rename isReference to isReadOnlyReference
There is implicit knowledge that the reference is read only in the code
so we should honor that and make is explicit.

Change-Id: I0d6eab6595ae1414ad2607760a2e02fd49bafd72
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
2016-02-25 09:39:51 +00:00
Marco Bubke
1eb0c94f81 Utils: Add SmallString
SmallString is a very simple utf8 string class. It's purpose is performance.
It uses a short string opimization which provides 31 bytes of heap free
memory to save a 30 bytes long string plus null terminator. If the string
gets larger heap is allocated. The grow strategy is 1.5 to improve reuse
of allocated memory.

It uses optionally constexpr to provide string literals.

Change-Id: I7757fb51abfeca200d074cbfce2f1d99edc0ecb0
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
2016-02-17 15:07:01 +00:00