summaryrefslogtreecommitdiff
path: root/src/libs/utils/smallstring.h
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2017-08-02 18:59:44 +0200
committerTim Jenssen <tim.jenssen@qt.io>2017-08-04 09:32:21 +0000
commit4cc89b97de0d227034f6f0eed56055b4eeb6378b (patch)
tree2d86d033da944db69651dc47a6782f39b946806c /src/libs/utils/smallstring.h
parent18453deafb34fcd911195bcebc01ec0bf8bb801f (diff)
downloadqt-creator-4cc89b97de0d227034f6f0eed56055b4eeb6378b.tar.gz
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>
Diffstat (limited to 'src/libs/utils/smallstring.h')
-rw-r--r--src/libs/utils/smallstring.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/libs/utils/smallstring.h b/src/libs/utils/smallstring.h
index df17b7f30c..6c489c01d8 100644
--- a/src/libs/utils/smallstring.h
+++ b/src/libs/utils/smallstring.h
@@ -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);