Commit 293fb197 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port to QVector

parent 765cdeb4
......@@ -20,6 +20,7 @@
#include "riceencodingdecodertest.h"
#include "../riceencodingdecoder.h"
#include <QTest>
#include <QVector>
RiceEncodingDecoderTest::RiceEncodingDecoderTest(QObject *parent)
: QObject(parent)
......@@ -65,14 +66,14 @@ void RiceEncodingDecoderTest::shouldDecodeRiceIndices()
QFETCH(int, riceParameter);
QFETCH(int, numberEntries);
QFETCH(QByteArray, encodingData);
QFETCH(QList<quint32>, result);
QFETCH(QVector<quint32>, result);
WebEngineViewer::RiceEncodingDecoder decoding;
WebEngineViewer::RiceDeltaEncoding deltaEncoding;
deltaEncoding.encodingData = encodingData;
deltaEncoding.firstValue = firstValue;
deltaEncoding.numberEntries = numberEntries;
deltaEncoding.riceParameter = riceParameter;
QList<quint32> list = decoding.decodeRiceIndiceDelta(deltaEncoding);
QVector<quint32> list = decoding.decodeRiceIndiceDelta(deltaEncoding);
QCOMPARE(list.count(), result.count());
QCOMPARE(list, result);
}
......@@ -83,8 +84,8 @@ void RiceEncodingDecoderTest::shouldDecodeRiceHashes_data()
QTest::addColumn<int>("riceParameter");
QTest::addColumn<int>("numberEntries");
QTest::addColumn<QByteArray>("encodingData");
QTest::addColumn<QList<quint32> >("result");
QList<quint32> r;
QTest::addColumn<QVector<quint32> >("result");
QVector<quint32> r;
QTest::newRow("empty") << QByteArray() << 0 << 0 << QByteArray() << r;
r.clear();
r = {5, 0xad934c0cu, 0x6ff67f56u, 0x81316fceu};
......@@ -97,14 +98,14 @@ void RiceEncodingDecoderTest::shouldDecodeRiceHashes()
QFETCH(int, riceParameter);
QFETCH(int, numberEntries);
QFETCH(QByteArray, encodingData);
QFETCH(QList<quint32>, result);
QFETCH(QVector<quint32>, result);
WebEngineViewer::RiceEncodingDecoder decoding;
WebEngineViewer::RiceDeltaEncoding deltaEncoding;
deltaEncoding.encodingData = encodingData;
deltaEncoding.firstValue = firstValue;
deltaEncoding.numberEntries = numberEntries;
deltaEncoding.riceParameter = riceParameter;
const QList<quint32> hash = decoding.decodeRiceHashesDelta(deltaEncoding);
const QVector<quint32> hash = decoding.decodeRiceHashesDelta(deltaEncoding);
qDebug() << " hash " << hash << " 0xad934c0cu" << 0xad934c0cu;
QCOMPARE(hash, result);
}
......
......@@ -84,7 +84,7 @@ void CreateDatabaseFileJobPrivate::createFileFromFullUpdate(const QVector<Additi
{
//TODO
qCWarning(WEBENGINEVIEWER_LOG) << "Rice compression still not implemented";
const QList<quint32> listRice = WebEngineViewer::RiceEncodingDecoder::decodeRiceHashesDelta(add.riceDeltaEncoding);
const QVector<quint32> listRice = WebEngineViewer::RiceEncodingDecoder::decodeRiceHashesDelta(add.riceDeltaEncoding);
qDebug() << " listRice" << listRice;
break;
}
......@@ -174,7 +174,7 @@ void CreateDatabaseFileJobPrivate::generateFile(bool fullUpdate)
void CreateDatabaseFileJobPrivate::removeElementFromDataBase(const QVector<Removal> &removalList, QVector<Addition> &oldDataBaseAddition)
{
QList<quint32> indexToRemove;
QVector<quint32> indexToRemove;
for (const Removal &removeItem : removalList) {
switch (removeItem.compressionType) {
case UpdateDataBaseInfo::RawCompression:
......
......@@ -38,17 +38,17 @@ RiceEncodingDecoder::~RiceEncodingDecoder()
{
}
QList<quint32> RiceEncodingDecoder::decodeRiceIndiceDelta(const RiceDeltaEncoding &riceDeltaEncoding)
QVector<quint32> RiceEncodingDecoder::decodeRiceIndiceDelta(const RiceDeltaEncoding &riceDeltaEncoding)
{
bool ok;
QList<quint32> list;
QVector<quint32> list;
if (riceDeltaEncoding.firstValue.isEmpty()) {
return list;
}
quint64 firstValue = riceDeltaEncoding.firstValue.toInt(&ok);
if (!ok) {
qCWarning(WEBENGINEVIEWER_LOG) << "First value is not a int value " << riceDeltaEncoding.firstValue;
return QList<quint32>();
return QVector<quint32>();
}
list.reserve(riceDeltaEncoding.numberEntries + 1);
list << firstValue;
......@@ -62,7 +62,7 @@ QList<quint32> RiceEncodingDecoder::decodeRiceIndiceDelta(const RiceDeltaEncodin
quint32 offset;
bool result = decoder.nextValue(&offset);
if (!result) {
return QList<quint32>();
return QVector<quint32>();
}
lastValue += offset;
#if 0
......@@ -77,9 +77,9 @@ QList<quint32> RiceEncodingDecoder::decodeRiceIndiceDelta(const RiceDeltaEncodin
return list;
}
QList<quint32> RiceEncodingDecoder::decodeRiceHashesDelta(const RiceDeltaEncoding &riceDeltaEncoding)
QVector<quint32> RiceEncodingDecoder::decodeRiceHashesDelta(const RiceDeltaEncoding &riceDeltaEncoding)
{
QList<quint32> list;
QVector<quint32> list;
bool ok = false;
quint64 firstValue = riceDeltaEncoding.firstValue.toInt(&ok);
if (!ok) {
......@@ -96,7 +96,7 @@ QList<quint32> RiceEncodingDecoder::decodeRiceHashesDelta(const RiceDeltaEncodin
quint32 offset;
bool result = decoder.nextValue(&offset);
if (!result) {
return QList<quint32>();
return QVector<quint32>();
}
lastValue += offset;
......@@ -116,7 +116,7 @@ QList<quint32> RiceEncodingDecoder::decodeRiceHashesDelta(const RiceDeltaEncodin
// This flipping is done so that when the vector is interpreted as a string,
// the bytes are in the correct order.
QList<quint32> newList;
QVector<quint32> newList;
newList.reserve(list.count());
const int listCount(list.count());
for (int i = 0; i < listCount; ++i) {
......
......@@ -22,6 +22,7 @@
#include "webengineviewer_private_export.h"
#include "updatedatabaseinfo.h"
#include <QVector>
namespace WebEngineViewer {
//https://developers.google.com/safe-browsing/v4/compression
class RiceDecoder
......@@ -60,8 +61,8 @@ public:
RiceEncodingDecoder();
~RiceEncodingDecoder();
static QList<quint32> decodeRiceIndiceDelta(const WebEngineViewer::RiceDeltaEncoding &riceDeltaEncoding);
static QList<quint32> decodeRiceHashesDelta(const WebEngineViewer::RiceDeltaEncoding &riceDeltaEncoding);
static QVector<quint32> decodeRiceIndiceDelta(const WebEngineViewer::RiceDeltaEncoding &riceDeltaEncoding);
static QVector<quint32> decodeRiceHashesDelta(const WebEngineViewer::RiceDeltaEncoding &riceDeltaEncoding);
};
}
......
......@@ -29,6 +29,7 @@
#include <QWebEngineView>
#include <QToolTip>
#include <QDebug>
#include <QVector>
using namespace WebEngineViewer;
template<typename Arg, typename R, typename C>
struct InvokeWrapper {
......@@ -267,7 +268,7 @@ void WebEngineAccessKey::handleSearchAccessKey(const QVariant &res)
anchorList << WebEngineViewer::WebEngineAccessKeyAnchor(var);
}
QList<QChar> unusedKeys;
QVector<QChar> unusedKeys;
unusedKeys.reserve(10 + ('Z' - 'A' + 1));
for (char c = 'A'; c <= 'Z'; ++c) {
unusedKeys << QLatin1Char(c);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment