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>
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>
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>
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>
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>
Never forward declare STL container.
Change-Id: Ie2d222f858f555294581bbea90300755973cb54e
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
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>
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>
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>
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>
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>