summaryrefslogtreecommitdiff
path: root/src/qml/jsruntime/qv4internalclass.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-08-29 19:13:48 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-08-30 12:40:28 +0200
commit7910426730fb1e3384d946f953cb1ef1455e11d2 (patch)
tree18a60de68a4a0d48837ce45add8afd4ccaea285c /src/qml/jsruntime/qv4internalclass.cpp
parent4c3098ab106fae8f2ee256950cdbc8b8da29aa1b (diff)
downloadqtdeclarative-7910426730fb1e3384d946f953cb1ef1455e11d2.tar.gz
V4: Inline some PropertyAttribute storage
As PropertyAttribute is only one byte long, we can fit 4 or 8 of them into the space the pointer needs. Doing so avoids some allocations. Change-Id: Icea975d51d16eca7d4ace74c5763ea261b0bb8ea Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4internalclass.cpp')
-rw-r--r--src/qml/jsruntime/qv4internalclass.cpp48
1 files changed, 32 insertions, 16 deletions
diff --git a/src/qml/jsruntime/qv4internalclass.cpp b/src/qml/jsruntime/qv4internalclass.cpp
index c22a88f007..bd47d8efbc 100644
--- a/src/qml/jsruntime/qv4internalclass.cpp
+++ b/src/qml/jsruntime/qv4internalclass.cpp
@@ -141,11 +141,20 @@ SharedInternalClassDataPrivate<PropertyAttributes>::SharedInternalClassDataPriva
m_engine(other.m_engine)
{
Q_ASSERT(m_size <= m_alloc);
+ Q_ASSERT(m_alloc > 0);
+
m_engine->memoryManager->changeUnmanagedHeapSizeUsage(m_alloc * sizeof(PropertyAttributes));
- data = new PropertyAttributes[m_alloc];
- if (other.data)
- memcpy(data, other.data, (m_size - 1) * sizeof(PropertyAttributes));
- data[pos] = value;
+ const PropertyAttributes *source = other.m_alloc > NumAttributesInPointer
+ ? other.m_data
+ : other.m_inlineData;
+ PropertyAttributes *target;
+ if (m_alloc > NumAttributesInPointer)
+ m_data = target = new PropertyAttributes[m_alloc];
+ else
+ target = m_inlineData;
+
+ memcpy(target, source, (m_size - 1) * sizeof(PropertyAttributes));
+ target[pos] = value;
}
SharedInternalClassDataPrivate<PropertyAttributes>::SharedInternalClassDataPrivate(
@@ -155,12 +164,14 @@ SharedInternalClassDataPrivate<PropertyAttributes>::SharedInternalClassDataPriva
m_size(other.m_size),
m_engine(other.m_engine)
{
- if (m_alloc) {
- m_engine->memoryManager->changeUnmanagedHeapSizeUsage(m_alloc * sizeof(PropertyAttributes));
- data = new PropertyAttributes[m_alloc];
- memcpy(data, other.data, m_size*sizeof(PropertyAttributes));
+ m_engine->memoryManager->changeUnmanagedHeapSizeUsage(m_alloc * sizeof(PropertyAttributes));
+ if (m_alloc > NumAttributesInPointer) {
+ m_data = new PropertyAttributes[m_alloc];
+ memcpy(m_data, other.m_data, m_size*sizeof(PropertyAttributes));
+ } else if (m_alloc > 0) {
+ memcpy(m_inlineData, other.m_inlineData, m_alloc * sizeof(PropertyAttributes));
} else {
- data = nullptr;
+ m_data = nullptr;
}
}
@@ -168,13 +179,14 @@ SharedInternalClassDataPrivate<PropertyAttributes>::~SharedInternalClassDataPriv
{
m_engine->memoryManager->changeUnmanagedHeapSizeUsage(
-qptrdiff(m_alloc * sizeof(PropertyAttributes)));
- delete [] data;
+ if (m_alloc > NumAttributesInPointer)
+ delete [] m_data;
}
void SharedInternalClassDataPrivate<PropertyAttributes>::grow() {
uint alloc;
if (!m_alloc) {
- alloc = 8;
+ alloc = NumAttributesInPointer;
m_engine->memoryManager->changeUnmanagedHeapSizeUsage(alloc * sizeof(PropertyAttributes));
} else {
// yes, signed. We don't want to deal with stuff > 2G
@@ -188,12 +200,16 @@ void SharedInternalClassDataPrivate<PropertyAttributes>::grow() {
(alloc - m_alloc) * sizeof(PropertyAttributes));
}
- auto *n = new PropertyAttributes[alloc];
- if (data) {
- memcpy(n, data, m_alloc*sizeof(PropertyAttributes));
- delete [] data;
+ if (alloc > NumAttributesInPointer) {
+ auto *n = new PropertyAttributes[alloc];
+ if (m_alloc > NumAttributesInPointer) {
+ memcpy(n, m_data, m_alloc * sizeof(PropertyAttributes));
+ delete [] m_data;
+ } else if (m_alloc > 0) {
+ memcpy(n, m_inlineData, m_alloc * sizeof(PropertyAttributes));
+ }
+ m_data = n;
}
- data = n;
m_alloc = alloc;
}