From 58b4cf8722e80248885e38996d4688f471b73e4f Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 11 Mar 2015 13:27:01 +0100 Subject: 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 --- src/corelib/json/qjsonparser_p.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/corelib/json') diff --git a/src/corelib/json/qjsonparser_p.h b/src/corelib/json/qjsonparser_p.h index 98b23dc9c5..a395c0c92e 100644 --- a/src/corelib/json/qjsonparser_p.h +++ b/src/corelib/json/qjsonparser_p.h @@ -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 offsets; + QVector offsets; inline QJsonPrivate::Entry *entryAt(int i) const { return reinterpret_cast(parser->data + objectPosition + offsets[i]); -- cgit v1.2.1