Commit 47d8dcec authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port to QVector + reserve element

parent 7a53a4a2
......@@ -171,8 +171,9 @@ void SignJob::process()
QByteArray body = d->content->encodedBody();
bool changed = false;
QList<QByteArray> search;
search.reserve(3);
QList<QByteArray> replacements;
replacements.reserve(3);
search << "From "
<< "from "
<< "-";
......
......@@ -69,7 +69,7 @@ QList< MessageItem * > MessageItemSetManager::messageItems(MessageItemSetReferen
void MessageItemSetManager::removeMessageItemFromAllSets(MessageItem *mi)
{
QList< MessageItemSetReference > setsToBeKilled;
QVector< MessageItemSetReference > setsToBeKilled;
for (auto it = mSets->cbegin(), end = mSets->cend(); it != end; ++it) {
(*it)->remove(mi);
......
......@@ -32,7 +32,7 @@ void CryptoHelperTest::testPMFDEmpty()
void CryptoHelperTest::testPMFDWithNoPGPBlock()
{
const QByteArray text = "testblabla";
const QList<Block> blocks = prepareMessageForDecryption(text);
const QVector<Block> blocks = prepareMessageForDecryption(text);
QCOMPARE(blocks.count(), 1);
QCOMPARE(blocks[0].text(), text);
QCOMPARE(blocks[0].type(), NoPgpBlock);
......@@ -65,7 +65,7 @@ void CryptoHelperTest::testPGPBlockType()
break;
}
QString text = QLatin1String("-----BEGIN PGP ") + name + QLatin1Char('\n') + blockText;
QList<Block> blocks = prepareMessageForDecryption(preString.toLatin1() + text.toLatin1());
QVector<Block> blocks = prepareMessageForDecryption(preString.toLatin1() + text.toLatin1());
QCOMPARE(blocks.count(), 1);
QCOMPARE(blocks[0].type(), UnknownBlock);
......@@ -112,7 +112,7 @@ void CryptoHelperTest::testDeterminePGPBlockType()
void CryptoHelperTest::testEmbededPGPBlock()
{
const QByteArray text = QByteArray("before\n-----BEGIN PGP MESSAGE-----\ncrypted - you see :)\n-----END PGP MESSAGE-----\nafter");
const QList<Block> blocks = prepareMessageForDecryption(text);
const QVector<Block> blocks = prepareMessageForDecryption(text);
QCOMPARE(blocks.count(), 3);
QCOMPARE(blocks[0].text(), QByteArray("before\n"));
QCOMPARE(blocks[1].text(), QByteArray("-----BEGIN PGP MESSAGE-----\ncrypted - you see :)\n-----END PGP MESSAGE-----\n"));
......@@ -122,7 +122,7 @@ void CryptoHelperTest::testEmbededPGPBlock()
void CryptoHelperTest::testClearSignedMessage()
{
const QByteArray text = QByteArray("before\n-----BEGIN PGP SIGNED MESSAGE-----\nsigned content\n-----BEGIN PGP SIGNATURE-----\nfancy signature\n-----END PGP SIGNATURE-----\nafter");
const QList<Block> blocks = prepareMessageForDecryption(text);
const QVector<Block> blocks = prepareMessageForDecryption(text);
QCOMPARE(blocks.count(), 3);
QCOMPARE(blocks[0].text(), QByteArray("before\n"));
QCOMPARE(blocks[1].text(), QByteArray("-----BEGIN PGP SIGNED MESSAGE-----\nsigned content\n-----BEGIN PGP SIGNATURE-----\nfancy signature\n-----END PGP SIGNATURE-----\n"));
......@@ -133,7 +133,7 @@ void CryptoHelperTest::testMultipleBlockMessage()
{
const QByteArray text = QByteArray(
"before\n-----BEGIN PGP SIGNED MESSAGE-----\nsigned content\n-----BEGIN PGP SIGNATURE-----\nfancy signature\n-----END PGP SIGNATURE-----\nafter\n-----BEGIN PGP MESSAGE-----\ncrypted - you see :)\n-----END PGP MESSAGE-----\n");
const QList<Block> blocks = prepareMessageForDecryption(text);
const QVector<Block> blocks = prepareMessageForDecryption(text);
QCOMPARE(blocks.count(), 4);
QCOMPARE(blocks[0].text(), QByteArray("before\n"));
QCOMPARE(blocks[1].text(), QByteArray("-----BEGIN PGP SIGNED MESSAGE-----\nsigned content\n-----BEGIN PGP SIGNATURE-----\nfancy signature\n-----END PGP SIGNATURE-----\n"));
......
......@@ -44,10 +44,10 @@ PGPBlockType Block::determineType() const
}
}
QList<Block> MimeTreeParser::prepareMessageForDecryption(const QByteArray &msg)
QVector<Block> MimeTreeParser::prepareMessageForDecryption(const QByteArray &msg)
{
PGPBlockType pgpBlock = NoPgpBlock;
QList<Block> blocks;
QVector<Block> blocks;
int start = -1; // start of the current PGP block
int lastEnd = -1; // end of the last PGP block
const int length = msg.length();
......
......@@ -19,7 +19,7 @@
#define MIMETREEPARSER_CRYPTOHELPER_H
#include <QByteArray>
#include <QList>
#include <QVector>
namespace MimeTreeParser {
enum PGPBlockType {
......@@ -51,7 +51,7 @@ public:
/** Parses the given message and splits it into OpenPGP blocks and
Non-OpenPGP blocks.
*/
QList<Block> prepareMessageForDecryption(const QByteArray &msg);
QVector<Block> prepareMessageForDecryption(const QByteArray &msg);
} // namespace MimeTreeParser
Q_DECLARE_TYPEINFO(MimeTreeParser::Block, Q_MOVABLE_TYPE);
......
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