Fix quadratic behavior when parsing very large objects

QVarlengthArray is not a good data structure when you need
to dynamically append to it without knowing its size in advance,
as it reallocates on every append. Use a QVector instead.

Task-number: QTBUG-44737
Change-Id: I68eab11eacd8368e94943511874aead823a149ab
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Lars Knoll 2015-03-11 13:27:01 +01:00 committed by Lars Knoll
parent 56c8a19044
commit 58b4cf8722

View File

@ -62,12 +62,14 @@ public:
class ParsedObject
{
public:
ParsedObject(Parser *p, int pos) : parser(p), objectPosition(pos) {}
ParsedObject(Parser *p, int pos) : parser(p), objectPosition(pos) {
offsets.reserve(64);
}
void insert(uint offset);
Parser *parser;
int objectPosition;
QVarLengthArray<uint, 64> offsets;
QVector<uint> offsets;
inline QJsonPrivate::Entry *entryAt(int i) const {
return reinterpret_cast<QJsonPrivate::Entry *>(parser->data + objectPosition + offsets[i]);