aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2017-08-11 23:57:15 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2017-08-18 09:57:39 +0000
commitaf504fc0dabd65ac5a4eef2233ad87ed9a54c500 (patch)
treee94ffb9e114d7ce5f2264b00e6646d69e56652b0 /src
parentacce7faa54ae1837527ca574a174b9adba2265ac (diff)
Avoid lookup calls for constant values of the global object
undefined, Infinity and NaN can never be changed in the global object, so we can directly resolve them to constants in the parser. Change-Id: I0cf43ff299518921d914121e150bc64ae5ea0c6e Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/compiler/qv4codegen.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index 362f85c67e..a91a6e62e0 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -1358,6 +1358,14 @@ Codegen::Reference Codegen::referenceForName(const QString &name, bool isLhs)
}
if (!c->parent && !c->forceLookupByName() && _context->compilationMode != EvalCode && c->compilationMode != QmlBinding) {
+ // these value properties of the global object are immutable, we we can directly convert them
+ // to their numeric value here
+ if (name == QStringLiteral("undefined"))
+ return Reference::fromConst(this, Encode::undefined());
+ else if (name == QStringLiteral("Infinity"))
+ return Reference::fromConst(this, Encode(qInf()));
+ else if (name == QStringLiteral("Nan"))
+ return Reference::fromConst(this, Encode(qQNaN()));
Reference r = Reference::fromName(this, name);
r.global = true;
return r;