diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-09-07 15:47:18 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-09-25 08:38:00 +0000 |
commit | 81f8e599112471ee802d7fd7b0b79b7330348be6 (patch) | |
tree | 86c79674e79c26a7f25ea1fdca1bc7ff2531d195 /src/qml/jsruntime/qv4internalclass.cpp | |
parent | e255fdf207891765aa550709e084614242aebeec (diff) |
Speed up QQmlEngine constructor
Freezing the global object using a script is pretty slow,
esp. given that the script needs to be compiled as well. Rather
do it programmatically.
The old code actually had a bug that would only cause the global
object to be frozen, not it's children. The new code fixes this,
but doesn't completely freeze the objects. Instead it makes all
the existing properties of the global object and it's children
readonly, but still allows extending existing objects with new
properties.
Change-Id: I0d7331cdc89a0ac717b8ed3b1a490b2a3742de02
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/jsruntime/qv4internalclass.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4internalclass.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/qml/jsruntime/qv4internalclass.cpp b/src/qml/jsruntime/qv4internalclass.cpp index 87987f7d50..8f0b1776d7 100644 --- a/src/qml/jsruntime/qv4internalclass.cpp +++ b/src/qml/jsruntime/qv4internalclass.cpp @@ -399,20 +399,26 @@ InternalClass *InternalClass::frozen() if (m_frozen) return m_frozen; - m_frozen = engine->emptyClass; + m_frozen = propertiesFrozen(); + m_frozen = m_frozen->nonExtensible(); + + m_frozen->m_frozen = m_frozen; + m_frozen->m_sealed = m_frozen; + return m_frozen; +} + +InternalClass *InternalClass::propertiesFrozen() const +{ + InternalClass *frozen = engine->emptyClass; for (uint i = 0; i < size; ++i) { PropertyAttributes attrs = propertyData.at(i); if (attrs.isEmpty()) continue; attrs.setWritable(false); attrs.setConfigurable(false); - m_frozen = m_frozen->addMember(nameMap.at(i), attrs); + frozen = frozen->addMember(nameMap.at(i), attrs); } - m_frozen = m_frozen->nonExtensible(); - - m_frozen->m_frozen = m_frozen; - m_frozen->m_sealed = m_frozen; - return m_frozen; + return frozen; } void InternalClass::destroy() |