diff options
| author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-07-14 13:16:11 +0200 |
|---|---|---|
| committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-07-19 22:17:01 +0200 |
| commit | 71be7834e67216010dc74ed855dc7b513e302f1a (patch) | |
| tree | 639cf1244cfc47f372d19d46f8e5a98fdf9210a4 /src/corelib/kernel/qjniobject.h | |
| parent | ebbf7b0fdf866190cd20e62d6b13c7c6808101da (diff) | |
JNI: Improve the constraint on QJniArray::fromContainer
We can create a QJniArray from any container that has a forward
iterator. A contiguous container can be used to optimize the code path,
as long as the element type is primitive (i.e. not an object type).
Fixes: QTBUG-126151
Pick-to: 6.8
Change-Id: I21915f944d226d6d4f1113a54e5602ddc9cd727e
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/kernel/qjniobject.h')
| -rw-r--r-- | src/corelib/kernel/qjniobject.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/corelib/kernel/qjniobject.h b/src/corelib/kernel/qjniobject.h index e3168488fc7..c84effc160c 100644 --- a/src/corelib/kernel/qjniobject.h +++ b/src/corelib/kernel/qjniobject.h @@ -848,6 +848,16 @@ QT_END_NAMESPACE #include <QtCore/qjniarray.h> QT_BEGIN_NAMESPACE +namespace QtJniTypes { +namespace detail { +template <typename C> +using FromContainerTest = decltype(QJniArrayBase::fromContainer(std::declval<C>())); + +template <typename C> +static constexpr bool isCompatibleSourceContainer = qxp::is_detected_v<FromContainerTest, C>; +} +} + template <typename ...Args> template <typename T> auto QJniObject::LocalFrame<Args...>::convertToJni(T &&value) @@ -857,7 +867,7 @@ auto QJniObject::LocalFrame<Args...>::convertToJni(T &&value) return newLocalRef<jstring>(QJniObject::fromString(value)); } else if constexpr (QtJniTypes::IsJniArray<Type>::value) { return value.arrayObject(); - } else if constexpr (QJniArrayBase::isContiguousContainer<T>) { + } else if constexpr (QtJniTypes::detail::isCompatibleSourceContainer<T>) { using QJniArrayType = decltype(QJniArrayBase::fromContainer(std::forward<T>(value))); using ArrayType = decltype(std::declval<QJniArrayType>().arrayObject()); return newLocalRef<ArrayType>(QJniArrayBase::fromContainer(std::forward<T>(value)).template object<jobject>()); @@ -878,7 +888,7 @@ auto QJniObject::LocalFrame<Args...>::convertFromJni(QJniObject &&object) return object.toString(); } else if constexpr (QtJniTypes::IsJniArray<Type>::value) { return T(std::move(object)); - } else if constexpr (QJniArrayBase::isContiguousContainer<Type>) { + } else if constexpr (QtJniTypes::detail::isCompatibleSourceContainer<Type>) { // if we were to create a QJniArray from Type... using QJniArrayType = decltype(QJniArrayBase::fromContainer(std::declval<Type>())); // then that QJniArray would have elements of type |
