summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2018-10-31 19:13:29 -0700
committerThiago Macieira <thiago.macieira@intel.com>2018-12-11 03:57:41 +0000
commit57b4b45cbdee00f7e38e5eb57d2bcf42201dc74e (patch)
treea2492277053052cb1c01c014f3bf34b3feaa16b6
parent2c9ac4fc3fe0b8f39e7f7a93894b56e49fd3d887 (diff)
RCC: introduce compression algorithm "best"
This compression algorithm is permitted in the XML sources, which instructs RCC to apply the best compression algorithm it has available. If we have Zstandard available, that's its level 19 (levels 20 and up are experimental). If not, we apply zlib compression level 9. And apply this technique for the XDG MIME database that is built-in to QtCore. Payload size Compr. time Previously 313916 17.9ms Zlib -9 310899 53.6ms Zstd -14 253364 63.3ms (plus 4.0 ms on L1 heuristic check) Zstd -19 230647 642.5ms Change-Id: I343f2beed55440a7ac0bfffd1562de44dbaf09cd Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/corelib/mimetypes/mimetypes.qrc2
-rw-r--r--src/tools/rcc/rcc.cpp11
-rw-r--r--src/tools/rcc/rcc.h1
3 files changed, 13 insertions, 1 deletions
diff --git a/src/corelib/mimetypes/mimetypes.qrc b/src/corelib/mimetypes/mimetypes.qrc
index 19bc1d3e2a..4720bd302a 100644
--- a/src/corelib/mimetypes/mimetypes.qrc
+++ b/src/corelib/mimetypes/mimetypes.qrc
@@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/qt-project.org/qmime/packages">
- <file alias="freedesktop.org.xml">mime/packages/freedesktop.org.xml</file>
+ <file alias="freedesktop.org.xml" compression-algorithm="best">mime/packages/freedesktop.org.xml</file>
</qresource>
</RCC>
diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp
index dfa62cea1b..5cbc771994 100644
--- a/src/tools/rcc/rcc.cpp
+++ b/src/tools/rcc/rcc.cpp
@@ -258,6 +258,10 @@ qint64 RCCFileInfo::writeDataBlob(RCCResourceLibrary &lib, qint64 offset,
// Check if compression is useful for this file
if (data.size() != 0) {
#if QT_CONFIG(zstd)
+ if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Best) {
+ m_compressAlgo = RCCResourceLibrary::CompressionAlgorithm::Zstd;
+ m_compressLevel = 19; // not ZSTD_maxCLevel(), as 20+ are experimental
+ }
if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Zstd) {
if (lib.m_zstdCCtx == nullptr)
lib.m_zstdCCtx = ZSTD_createCCtx();
@@ -301,6 +305,10 @@ qint64 RCCFileInfo::writeDataBlob(RCCResourceLibrary &lib, qint64 offset,
}
#endif
#ifndef QT_NO_COMPRESS
+ if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Best) {
+ m_compressAlgo = RCCResourceLibrary::CompressionAlgorithm::Zlib;
+ m_compressLevel = 9;
+ }
if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Zlib) {
QByteArray compressed =
qCompress(reinterpret_cast<uchar *>(data.data()), data.size(), m_compressLevel);
@@ -824,6 +832,8 @@ RCCResourceLibrary::ResourceDataFileMap RCCResourceLibrary::resourceDataFileMap(
RCCResourceLibrary::CompressionAlgorithm RCCResourceLibrary::parseCompressionAlgorithm(QStringView value, QString *errorMsg)
{
+ if (value == QLatin1String("best"))
+ return CompressionAlgorithm::Best;
if (value == QLatin1String("zlib")) {
#ifdef QT_NO_COMPRESS
*errorMsg = QLatin1String("zlib support not compiled in");
@@ -850,6 +860,7 @@ int RCCResourceLibrary::parseCompressionLevel(CompressionAlgorithm algo, const Q
if (ok) {
switch (algo) {
case CompressionAlgorithm::None:
+ case CompressionAlgorithm::Best:
return 0;
case CompressionAlgorithm::Zlib:
if (c >= 1 && c <= 9)
diff --git a/src/tools/rcc/rcc.h b/src/tools/rcc/rcc.h
index fe8ed21fb3..7603a41cde 100644
--- a/src/tools/rcc/rcc.h
+++ b/src/tools/rcc/rcc.h
@@ -84,6 +84,7 @@ public:
Zlib,
Zstd,
+ Best = 99,
None = -1
};