summaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-08-16 11:45:27 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-08-17 11:06:16 +0000
commit29e4b97bad6511ebd6aa009a47594395957c0e8e (patch)
tree32ba86bf9105b4468dc94cb5bc0191d5f0512237 /src/qml/jsruntime
parentf43c1d902d908c6cd523b0174338ac0c98a30647 (diff)
Add support for disk caching of ES modules
Two minor fixes needed for this otherwise straight-forward change: (1) When compiling modules, use the full url for the source file of the compilation unit, as that's what we use for the relocation check when loading the cache file. (2) Record the proper source time stamp for cache invalidation. As a bonus, when importing scripts from .qml files, we now also attempt to use the cached version that we created on the fly in an effort to replace heap memory with mmap backed memory - just like we do for .qml files. Change-Id: I5b03a18e3c44d537c3242cb1d969636df32fe42a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4engine.cpp14
-rw-r--r--src/qml/jsruntime/qv4engine_p.h4
2 files changed, 11 insertions, 7 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 14bc5f084e..c5eec33d18 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -1633,17 +1633,19 @@ QQmlRefPointer<CompiledData::CompilationUnit> ExecutionEngine::compileModule(con
return nullptr;
}
+ const QDateTime timeStamp = QFileInfo(f).lastModified();
+
const QString sourceCode = QString::fromUtf8(f.readAll());
f.close();
- return compileModule(url, sourceCode);
+ return compileModule(url, sourceCode, timeStamp);
}
-QQmlRefPointer<CompiledData::CompilationUnit> ExecutionEngine::compileModule(const QUrl &url, const QString &sourceCode)
+QQmlRefPointer<CompiledData::CompilationUnit> ExecutionEngine::compileModule(const QUrl &url, const QString &sourceCode, const QDateTime &sourceTimeStamp)
{
QList<QQmlJS::DiagnosticMessage> diagnostics;
- auto unit = compileModule(/*debugMode*/debugger() != nullptr, url, sourceCode, &diagnostics);
+ auto unit = compileModule(/*debugMode*/debugger() != nullptr, url, sourceCode, sourceTimeStamp, &diagnostics);
for (const QQmlJS::DiagnosticMessage &m : diagnostics) {
if (m.isError()) {
throwSyntaxError(m.message, url.toString(), m.loc.startLine, m.loc.startColumn);
@@ -1656,7 +1658,8 @@ QQmlRefPointer<CompiledData::CompilationUnit> ExecutionEngine::compileModule(con
return unit;
}
-QQmlRefPointer<CompiledData::CompilationUnit> ExecutionEngine::compileModule(bool debugMode, const QUrl &url, const QString &sourceCode, QList<QQmlJS::DiagnosticMessage> *diagnostics)
+QQmlRefPointer<CompiledData::CompilationUnit> ExecutionEngine::compileModule(bool debugMode, const QUrl &url, const QString &sourceCode,
+ const QDateTime &sourceTimeStamp, QList<QQmlJS::DiagnosticMessage> *diagnostics)
{
QQmlJS::Engine ee;
QQmlJS::Lexer lexer(&ee);
@@ -1683,9 +1686,10 @@ QQmlRefPointer<CompiledData::CompilationUnit> ExecutionEngine::compileModule(boo
using namespace QV4::Compiler;
Compiler::Module compilerModule(debugMode);
compilerModule.unitFlags |= CompiledData::Unit::IsESModule;
+ compilerModule.sourceTimeStamp = sourceTimeStamp;
JSUnitGenerator jsGenerator(&compilerModule);
Codegen cg(&jsGenerator, /*strictMode*/true);
- cg.generateFromModule(url.fileName(), url.toString(), sourceCode, moduleNode, &compilerModule);
+ cg.generateFromModule(url.toString(), url.toString(), sourceCode, moduleNode, &compilerModule);
auto errors = cg.errors();
if (diagnostics)
*diagnostics << errors;
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h
index 8312adee48..c8f8efaebf 100644
--- a/src/qml/jsruntime/qv4engine_p.h
+++ b/src/qml/jsruntime/qv4engine_p.h
@@ -577,8 +577,8 @@ public:
#ifndef V4_BOOTSTRAP
QQmlRefPointer<CompiledData::CompilationUnit> compileModule(const QUrl &url);
- QQmlRefPointer<CompiledData::CompilationUnit> compileModule(const QUrl &url, const QString &sourceCode);
- static QQmlRefPointer<CompiledData::CompilationUnit> compileModule(bool debugMode, const QUrl &url, const QString &sourceCode, QList<QQmlJS::DiagnosticMessage> *diagnostics);
+ QQmlRefPointer<CompiledData::CompilationUnit> compileModule(const QUrl &url, const QString &sourceCode, const QDateTime &sourceTimeStamp);
+ static QQmlRefPointer<CompiledData::CompilationUnit> compileModule(bool debugMode, const QUrl &url, const QString &sourceCode, const QDateTime &sourceTimeStamp, QList<QQmlJS::DiagnosticMessage> *diagnostics);
mutable QMutex moduleMutex;
QHash<QUrl, QQmlRefPointer<CompiledData::CompilationUnit>> modules;