forked from qt-creator/qt-creator
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:
@@ -258,6 +258,8 @@ public:
|
||||
m_data.allocated.data.pointer = Memory::reallocate(m_data.allocated.data.pointer,
|
||||
newCapacity + 1);
|
||||
m_data.allocated.data.capacity = newCapacity;
|
||||
} else if (newCapacity <= shortStringCapacity()) {
|
||||
new (this) BasicSmallString{m_data.allocated.data.pointer, m_data.allocated.data.size};
|
||||
} else {
|
||||
const size_type oldSize = size();
|
||||
newCapacity = std::max(newCapacity, oldSize);
|
||||
|
||||
Reference in New Issue
Block a user