From 57b4b45cbdee00f7e38e5eb57d2bcf42201dc74e Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 31 Oct 2018 19:13:29 -0700 Subject: [PATCH] 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 Reviewed-by: Lars Knoll --- src/corelib/mimetypes/mimetypes.qrc | 2 +- src/tools/rcc/rcc.cpp | 11 +++++++++++ src/tools/rcc/rcc.h | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/corelib/mimetypes/mimetypes.qrc b/src/corelib/mimetypes/mimetypes.qrc index 19bc1d3e2a9..4720bd302ac 100644 --- a/src/corelib/mimetypes/mimetypes.qrc +++ b/src/corelib/mimetypes/mimetypes.qrc @@ -1,5 +1,5 @@ - mime/packages/freedesktop.org.xml + mime/packages/freedesktop.org.xml diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp index dfa62cea1be..5cbc7719942 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(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 fe8ed21fb3c..7603a41cdea 100644 --- a/src/tools/rcc/rcc.h +++ b/src/tools/rcc/rcc.h @@ -84,6 +84,7 @@ public: Zlib, Zstd, + Best = 99, None = -1 };