aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2017-03-16 10:02:24 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2017-03-22 12:17:49 +0000
commit110f69ab8168950be74779b635d46ef83553d71a (patch)
tree06d7a1e39e70e2e714f7ae5a266cc94d169689a8 /src/qml/qml
parent5bd11b5a8c2f627bc9c9f1b6c02602772ad67dae (diff)
Speed up source code reading
Since we always convert the source code of .qml/.js/qmldir files from utf-8 to utf-16, we always end up copying bytes around. That means instead of allocating memory on the C++ heap and copying bytes from kernel space to user space and then a few times through QIODevice buffers until we reach QString::fromUtf8, we might as well mmap() the file directly - if possible. Change-Id: I54c88d4d9f03f9967130d65a7b53cfec93734018 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/qml')
-rw-r--r--src/qml/qml/qqmltypeloader.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp
index 9526615c0d..eedb649ef6 100644
--- a/src/qml/qml/qqmltypeloader.cpp
+++ b/src/qml/qml/qqmltypeloader.cpp
@@ -3086,7 +3086,15 @@ QString QQmlDataBlob::SourceCodeData::readAll(QString *error) const
return QString();
}
- QByteArray data(fileInfo.size(), Qt::Uninitialized);
+ const qint64 fileSize = fileInfo.size();
+
+ if (uchar *mappedData = f.map(0, fileSize)) {
+ QString source = QString::fromUtf8(reinterpret_cast<const char *>(mappedData), fileSize);
+ f.unmap(mappedData);
+ return source;
+ }
+
+ QByteArray data(fileSize, Qt::Uninitialized);
if (f.read(data.data(), data.length()) != data.length()) {
*error = f.errorString();
return QString();