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>
This commit is contained in:
Marco Bubke
2017-08-02 18:59:44 +02:00
committed by Tim Jenssen
parent 18453deafb
commit 4cc89b97de
2 changed files with 11 additions and 0 deletions

View File

@@ -914,6 +914,15 @@ TEST(SmallString, ReserveSmallerThanShortStringCapacity)
ASSERT_THAT(text.capacity(), AnyOf(30, 4));
}
TEST(SmallString, ReserveSmallerThanShortStringCapacityIsShortString)
{
SmallString text("text");
text.reserve(2);
ASSERT_TRUE(text.isShortString());
}
TEST(SmallString, ReserveSmallerThanReference)
{
SmallString text("some very very very very very very very very very very very long string");