JNI: merge QJniObject::toString implementation and helper

Both functions are short, and the helper is not reused by other code.
Merge them together so that we can (perhaps later) optimize the repeated
QJniEnvironment construction away.

Change-Id: I168a0620bc4ffbd259ddc3adc6472cfebd11fc5d
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
Reviewed-by: Zoltan Gera <zoltan.gera@qt.io>
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
This commit is contained in:
Volker Hilsheimer 2023-09-20 23:44:45 +02:00
parent f826d1615a
commit 19ce55c3b1

View File

@ -308,15 +308,6 @@ static inline QLatin1StringView keyBase()
return "%1%2:%3"_L1;
}
static QString qt_convertJString(jstring string)
{
QJniEnvironment env;
int strLength = env->GetStringLength(string);
QString res(strLength, Qt::Uninitialized);
env->GetStringRegion(string, 0, strLength, reinterpret_cast<jchar *>(res.data()));
return res;
}
typedef QHash<QString, jclass> JClassHash;
Q_GLOBAL_STATIC(JClassHash, cachedClasses)
Q_GLOBAL_STATIC(QReadWriteLock, cachedClassesLock)
@ -1349,7 +1340,11 @@ QString QJniObject::toString() const
return QString();
QJniObject string = callObjectMethod<jstring>("toString");
return qt_convertJString(static_cast<jstring>(string.object()));
QJniEnvironment env;
const int strLength = env->GetStringLength(string.object<jstring>());
QString res(strLength, Qt::Uninitialized);
env->GetStringRegion(string.object<jstring>(), 0, strLength, reinterpret_cast<jchar *>(res.data()));
return res;
}
/*!