Android: iterate over const QJniArray

If/when we introduce mutable QJniArray iterators, then iterating over a
mutable array will be significantly more expensive due to the write-back
from the reference type.

Change-Id: I2e8eb357fdb6a9890699f5c61d49b635d303f301
Reviewed-by: Soheil Armin <soheil.armin@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit 2d4f4220dd068c1253e701cdf6aefab17ef91c75)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Volker Hilsheimer 2024-09-19 09:35:43 +02:00 committed by Qt Cherry-pick Bot
parent 7413f60436
commit fd3482ea97

View File

@ -67,9 +67,9 @@ QHash<int, QByteArray> QAndroidItemModelProxy::roleNames() const
QHash<int, QByteArray> roleNames;
HashMap hashMap = jInstance.callMethod<HashMap>("roleNames");
Set set = hashMap.callMethod<Set>("keySet");
QJniArray<jobject> keyArray = set.callMethod<QJniArray<jobject>>("toArray");
const QJniArray keyArray = set.callMethod<jobject[]>("toArray");
for (auto key : keyArray) {
for (const auto &key : keyArray) {
const QJniObject roleName = hashMap.callMethod<jobject>("get", key);
const int intKey = QJniObject(key).callMethod<jint>("intValue");
const QByteArray roleByteArray = String(roleName).toString().toLatin1();