From 57b4b45cbdee00f7e38e5eb57d2bcf42201dc74e Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 31 Oct 2018 19:13:29 -0700 Subject: 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/tools/rcc/rcc.cpp | 11 +++++++++++ src/tools/rcc/rcc.h | 1 + 2 files changed, 12 insertions(+) (limited to 'src/tools/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(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 }; -- cgit v1.2.3