From 110f69ab8168950be74779b635d46ef83553d71a Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 16 Mar 2017 10:02:24 +0100 Subject: 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 --- src/qml/qml/qqmltypeloader.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/qml/qml') 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(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(); -- cgit v1.2.3