diff options
author | Lars Knoll <lars.knoll@qt.io> | 2019-11-25 17:53:55 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2019-12-08 18:20:24 +0100 |
commit | db89349bdba2fcc03b2f7e2d23f549a9ec5dc0e3 (patch) | |
tree | ecd7be12019b215dab88cf1b10118bad02271a20 /src/corelib/tools | |
parent | f247e94b51a825b09c33ad09098622677801a3b8 (diff) |
Optimize QArrayDataOps::compare for primitive types
Change-Id: If726e3ee8a3635dcec2a316f1a829392de298634
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qarraydataops.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index 8ca181edf1..f3de6b65a9 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -199,6 +199,11 @@ struct QPodArrayOps bool compare(const T *begin1, const T *begin2, size_t n) const { + // only use memcmp for fundamental types or pointers. + // Other types could have padding in the data structure or custom comparison + // operators that would break the comparison using memcmp + if (QArrayDataPointer<T>::pass_parameter_by_value) + return ::memcmp(begin1, begin2, n * sizeof(T)) == 0; const T *end1 = begin1 + n; while (begin1 != end1) { if (*begin1 == *begin2) |