diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2016-06-06 11:46:01 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2016-06-17 09:06:01 +0000 |
commit | 8a33d37006e8ad9010fe076105ada9f1ca5d9871 (patch) | |
tree | 37e95149dce4f164c495157b9fb1b78ff756dab4 /src/qml/compiler/qv4compileddata.cpp | |
parent | 0dfd0a1c09e36bb80c575c097ea6a5809df5e640 (diff) | |
download | qtdeclarative-8a33d37006e8ad9010fe076105ada9f1ca5d9871.tar.gz |
Added basic support for saving compilation units to disk
Hidden behind a QML_DISK_CACHE=1 environment variable we will now attempt to
save a binary representation of the type compilation for Foo.qml next to it called
Foo.qmlc.
Change-Id: I27e800b50cdb186669256fd277578ea1f1e70513
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compileddata.cpp')
-rw-r--r-- | src/qml/compiler/qv4compileddata.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp index a97902e2a0..d2587a547c 100644 --- a/src/qml/compiler/qv4compileddata.cpp +++ b/src/qml/compiler/qv4compileddata.cpp @@ -50,6 +50,7 @@ #include <private/qqmltypeloader_p.h> #include <private/qqmlengine_p.h> #include <QQmlPropertyMap> +#include <QSaveFile> #endif #include <private/qqmlirbuilder_p.h> #include <QCoreApplication> @@ -266,6 +267,63 @@ void CompilationUnit::updateBindingAndObjectCounters() totalParserStatusCount = parserStatusCount; totalObjectCount = objectCount; } + +bool CompilationUnit::saveToDisk(QString *errorString) +{ + errorString->clear(); + + const QUrl unitUrl = url(); + if (!unitUrl.isLocalFile()) { + *errorString = QStringLiteral("File has to be a local file."); + return false; + } + + // Foo.qml -> Foo.qmlc + QSaveFile cacheFile(unitUrl.toLocalFile() + QLatin1Char('c')); + if (!cacheFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + *errorString = cacheFile.errorString(); + return false; + } + + QByteArray modifiedUnit; + modifiedUnit.resize(data->unitSize); + memcpy(modifiedUnit.data(), data, data->unitSize); + const char *dataPtr = modifiedUnit.data(); + Unit *unitPtr; + memcpy(&unitPtr, &dataPtr, sizeof(unitPtr)); + unitPtr->flags |= Unit::StaticData; + + prepareCodeOffsetsForDiskStorage(unitPtr); + + qint64 headerWritten = cacheFile.write(modifiedUnit); + if (headerWritten != modifiedUnit.size()) { + *errorString = cacheFile.errorString(); + return false; + } + + if (!saveCodeToDisk(&cacheFile, unitPtr, errorString)) + return false; + + if (!cacheFile.commit()) { + *errorString = cacheFile.errorString(); + return false; + } + + return true; +} + +void CompilationUnit::prepareCodeOffsetsForDiskStorage(Unit *unit) +{ + Q_UNUSED(unit); +} + +bool CompilationUnit::saveCodeToDisk(QIODevice *device, const Unit *unit, QString *errorString) +{ + Q_UNUSED(device); + Q_UNUSED(unit); + *errorString = QStringLiteral("Saving code to disk is not supported in this configuration"); + return false; +} #endif // V4_BOOTSTRAP Unit *CompilationUnit::createUnitData(QmlIR::Document *irDocument) |