From 862fa24179505ef725ff78bb64bdabd54bd00c95 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 20 May 2016 23:56:19 +0200 Subject: 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 --- src/corelib/json/qjson_p.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/corelib/json/qjson_p.h') 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) -- cgit v1.2.3