From 19ce55c3b1b7fb4a0a2eadbe78a726c0b2ce486e Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 20 Sep 2023 23:44:45 +0200 Subject: [PATCH] JNI: merge QJniObject::toString implementation and helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ä Reviewed-by: Zoltan Gera Reviewed-by: Juha Vuolle --- src/corelib/kernel/qjniobject.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/corelib/kernel/qjniobject.cpp b/src/corelib/kernel/qjniobject.cpp index 20c28dee5ba..ca159b7891c 100644 --- a/src/corelib/kernel/qjniobject.cpp +++ b/src/corelib/kernel/qjniobject.cpp @@ -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(res.data())); - return res; -} - typedef QHash JClassHash; Q_GLOBAL_STATIC(JClassHash, cachedClasses) Q_GLOBAL_STATIC(QReadWriteLock, cachedClassesLock) @@ -1349,7 +1340,11 @@ QString QJniObject::toString() const return QString(); QJniObject string = callObjectMethod("toString"); - return qt_convertJString(static_cast(string.object())); + QJniEnvironment env; + const int strLength = env->GetStringLength(string.object()); + QString res(strLength, Qt::Uninitialized); + env->GetStringRegion(string.object(), 0, strLength, reinterpret_cast(res.data())); + return res; } /*!