aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4compilationunitmapper.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2016-08-09 11:09:24 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2016-08-09 09:44:00 +0000
commit186887aa56b68a2c0d9049759415db7307123137 (patch)
tree98b0246dad22941d84c1cd057bddd2ccd66ae2a7 /src/qml/compiler/qv4compilationunitmapper.cpp
parent3cba637ea6b4109171e5cab678f5ccecaed40809 (diff)
Reduce file descriptor pressure on Unix platforms
When opening cached compilation units, we can close the file descriptor after mmap'ing the contents, on Unix platforms. Change-Id: Ifb797a69743ebdc5e55db0b2e52b5cd66d071ca3 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compilationunitmapper.cpp')
-rw-r--r--src/qml/compiler/qv4compilationunitmapper.cpp57
1 files changed, 36 insertions, 21 deletions
diff --git a/src/qml/compiler/qv4compilationunitmapper.cpp b/src/qml/compiler/qv4compilationunitmapper.cpp
index 1d8be036c9..084137f17f 100644
--- a/src/qml/compiler/qv4compilationunitmapper.cpp
+++ b/src/qml/compiler/qv4compilationunitmapper.cpp
@@ -53,6 +53,40 @@ CompilationUnitMapper::CompilationUnitMapper()
}
+CompilationUnitMapper::~CompilationUnitMapper()
+{
+ close();
+}
+
+bool CompilationUnitMapper::verifyHeader(const CompiledData::Unit *header, const QString &sourcePath, QString *errorString)
+{
+ if (strncmp(header->magic, CompiledData::magic_str, sizeof(header->magic))) {
+ *errorString = QStringLiteral("Magic bytes in the header do not match");
+ return false;
+ }
+
+ if (header->version != quint32(QV4_DATA_STRUCTURE_VERSION)) {
+ *errorString = QString::fromUtf8("V4 data structure version mismatch. Found %1 expected %2").arg(header->version, 0, 16).arg(QV4_DATA_STRUCTURE_VERSION, 0, 16);
+ return false;
+ }
+
+ if (header->qtVersion != quint32(QT_VERSION)) {
+ *errorString = QString::fromUtf8("Qt version mismatch. Found %1 expected %2").arg(header->qtVersion, 0, 16).arg(QT_VERSION, 0, 16);
+ return false;
+ }
+
+ {
+ QFileInfo sourceCode(sourcePath);
+ if (sourceCode.exists() && sourceCode.lastModified().toMSecsSinceEpoch() != header->sourceTimeStamp) {
+ *errorString = QStringLiteral("QML source file has a different time stamp than cached file.");
+ return false;
+ }
+ }
+
+ return true;
+}
+
+#if !defined(Q_OS_UNIX)
CompiledData::Unit *CompilationUnitMapper::open(const QString &sourcePath, QString *errorString)
{
close();
@@ -71,28 +105,8 @@ CompiledData::Unit *CompilationUnitMapper::open(const QString &sourcePath, QStri
return nullptr;
}
- if (strncmp(header.magic, CompiledData::magic_str, sizeof(header.magic))) {
- *errorString = QStringLiteral("Magic bytes in the header do not match");
+ if (!verifyHeader(&header, sourcePath, errorString))
return nullptr;
- }
-
- if (header.version != quint32(QV4_DATA_STRUCTURE_VERSION)) {
- *errorString = QString::fromUtf8("V4 data structure version mismatch. Found %1 expected %2").arg(header.version, 0, 16).arg(QV4_DATA_STRUCTURE_VERSION, 0, 16);
- return nullptr;
- }
-
- if (header.qtVersion != quint32(QT_VERSION)) {
- *errorString = QString::fromUtf8("Qt version mismatch. Found %1 expected %2").arg(header.qtVersion, 0, 16).arg(QT_VERSION, 0, 16);
- return nullptr;
- }
-
- {
- QFileInfo sourceCode(sourcePath);
- if (sourceCode.exists() && sourceCode.lastModified().toMSecsSinceEpoch() != header.sourceTimeStamp) {
- *errorString = QStringLiteral("QML source file has a different time stamp than cached file.");
- return nullptr;
- }
- }
// Data structure and qt version matched, so now we can access the rest of the file safely.
@@ -110,5 +124,6 @@ void CompilationUnitMapper::close()
f.close();
dataPtr = nullptr;
}
+#endif // !defined(Q_OS_UNIX)
QT_END_NAMESPACE