diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-03-11 13:27:01 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@digia.com> | 2015-03-12 07:21:21 +0000 |
commit | 58b4cf8722e80248885e38996d4688f471b73e4f (patch) | |
tree | 77dd0eed346b0dd7697be8783edd36fc19909e8e /src/corelib | |
parent | 56c8a1904447c06f40d8605daaf7a9e433fc1b96 (diff) | |
download | qtbase-58b4cf8722e80248885e38996d4688f471b73e4f.tar.gz |
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>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/json/qjsonparser_p.h | 6 |
1 files changed, 4 insertions, 2 deletions
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<uint, 64> offsets; + QVector<uint> offsets; inline QJsonPrivate::Entry *entryAt(int i) const { return reinterpret_cast<QJsonPrivate::Entry *>(parser->data + objectPosition + offsets[i]); |