QDecompressHelper: port some methods to QBAV

Change-Id: I907019f19cbf4f6086fd6480ea9e01f5ab63b004
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Anton Kudryavtsev 2023-09-01 14:18:27 +03:00
parent d9620f0660
commit 5f032cdeff
2 changed files with 9 additions and 9 deletions

View File

@ -24,7 +24,7 @@ QT_BEGIN_NAMESPACE
namespace {
struct ContentEncodingMapping
{
char name[8];
QByteArrayView name;
QDecompressHelper::ContentEncoding encoding;
};
@ -39,10 +39,10 @@ constexpr ContentEncodingMapping contentEncodingMapping[] {
{ "deflate", QDecompressHelper::Deflate },
};
QDecompressHelper::ContentEncoding encodingFromByteArray(const QByteArray &ce) noexcept
QDecompressHelper::ContentEncoding encodingFromByteArray(QByteArrayView ce) noexcept
{
for (const auto &mapping : contentEncodingMapping) {
if (ce.compare(QByteArrayView(mapping.name, strlen(mapping.name)), Qt::CaseInsensitive) == 0)
if (ce.compare(mapping.name, Qt::CaseInsensitive) == 0)
return mapping.encoding;
}
return QDecompressHelper::None;
@ -68,7 +68,7 @@ ZSTD_DStream *toZstandardPointer(void *ptr)
#endif
}
bool QDecompressHelper::isSupportedEncoding(const QByteArray &encoding)
bool QDecompressHelper::isSupportedEncoding(QByteArrayView encoding)
{
return encodingFromByteArray(encoding) != QDecompressHelper::None;
}
@ -77,9 +77,9 @@ QByteArrayList QDecompressHelper::acceptedEncoding()
{
static QByteArrayList accepted = []() {
QByteArrayList list;
list.reserve(sizeof(contentEncodingMapping) / sizeof(contentEncodingMapping[0]));
list.reserve(std::size(contentEncodingMapping));
for (const auto &mapping : contentEncodingMapping) {
list << QByteArray(mapping.name);
list << mapping.name.toByteArray();
}
return list;
}();
@ -91,7 +91,7 @@ QDecompressHelper::~QDecompressHelper()
clear();
}
bool QDecompressHelper::setEncoding(const QByteArray &encoding)
bool QDecompressHelper::setEncoding(QByteArrayView encoding)
{
Q_ASSERT(contentEncoding == QDecompressHelper::None);
if (contentEncoding != QDecompressHelper::None) {

View File

@ -37,7 +37,7 @@ public:
QDecompressHelper() = default;
~QDecompressHelper();
bool setEncoding(const QByteArray &contentEncoding);
bool setEncoding(QByteArrayView contentEncoding);
bool isCountingBytes() const;
void setCountingBytesEnabled(bool shouldCount);
@ -57,7 +57,7 @@ public:
void setDecompressedSafetyCheckThreshold(qint64 threshold);
static bool isSupportedEncoding(const QByteArray &encoding);
static bool isSupportedEncoding(QByteArrayView encoding);
static QByteArrayList acceptedEncoding();
QString errorString() const;