path: root/src/corelib/json/qjson_p.h
diff options
authorMarc Mutz <>2016-05-20 23:56:19 +0200
committerMarc Mutz <>2016-06-08 04:38:20 +0000
commit862fa24179505ef725ff78bb64bdabd54bd00c95 (patch)
tree3f6012291d492a461b6742eb93b2208649a24df2 /src/corelib/json/qjson_p.h
parentf9c60038bf098015172998c2a216dd02672cd96b (diff)
Optimize QJsonObject::operator==
The old code iterated through one QJsonObject and looked up the key in the other, comparing the values. It had linearithmic complexity, and created one QString 'key' per element. Since the entries in a QJsonObject are lexicographically ordered, we can, however, just walk through the two objects in lock-step and compare corresponding entries (at the same index) with each other. Doing so saves O(N) QString creations and QJsonObject::value() calls, and makes operator== linear in the number of elements. Change-Id: Ib46ee0c1008b7f114454e282b6bd2bfcdbe59e2a Reviewed-by: Thiago Macieira <> Reviewed-by: Lars Knoll <>
Diffstat (limited to 'src/corelib/json/qjson_p.h')
1 files changed, 2 insertions, 0 deletions
diff --git a/src/corelib/json/qjson_p.h b/src/corelib/json/qjson_p.h
index c52a37ba2b..b7de24d165 100644
--- a/src/corelib/json/qjson_p.h
+++ b/src/corelib/json/qjson_p.h
@@ -670,6 +670,8 @@ public:
bool operator >=(const Entry &other) const;
+inline bool operator!=(const Entry &lhs, const Entry &rhs) { return !(lhs == rhs); }
inline bool Entry::operator >=(const QString &key) const
if (value.latinKey)