summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-01-18 10:36:33 +0100
committerUlf Hermann <ulf.hermann@qt.io>2022-01-21 00:53:49 +0100
commit9f1854acf8a13de98b5706d1246baa15f15f377e (patch)
treee8ec208c69c5f41289e4e9f846d6f153a9f7a0e1 /src
parent6c6b34206143edf77308c31ca2d68460c5c1c320 (diff)
JSON: Further improve the duplicate handling in the parser
Avoid some unnecessary comparisons and add more tests. Task-number: QTBUG-99799 Change-Id: I3aee9f0b62461d38dadbe8e969444e1cd1f94e68 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/serialization/qjsonparser.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/corelib/serialization/qjsonparser.cpp b/src/corelib/serialization/qjsonparser.cpp
index df66fc2772..d8d0ad9c2e 100644
--- a/src/corelib/serialization/qjsonparser.cpp
+++ b/src/corelib/serialization/qjsonparser.cpp
@@ -389,12 +389,24 @@ static Iterator customAssigningUniqueLast(Iterator first, Iterator last,
if (first == last)
return last;
- Iterator result = first;
+ // After adjacent_find, we know that *first and *(first+1) compare equal,
+ // and that first+1 != last.
+ Iterator result = first++;
+ Q_ASSERT(compare(*result, *first));
+ assign(*result, *first);
+ Q_ASSERT(first != last);
+
while (++first != last) {
if (!compare(*result, *first))
++result;
- if (result != first)
- assign(*result, *first);
+
+ // Due to adjacent_find above, we know that we've at least eliminated one element.
+ // Therefore we have to move each further element across the gap.
+ Q_ASSERT(result != first);
+
+ // We have to overwrite each element we want to eliminate, to deref() the container.
+ // Therefore we don't try to optimize the number of assignments here.
+ assign(*result, *first);
}
return ++result;