diff options
| author | JosJuice <josjuice@gmail.com> | 2026-01-24 20:42:31 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-24 20:42:31 +0100 |
| commit | 388b1e861cc42182c96fc78fb4bc41e87e84ef03 (patch) | |
| tree | 4021975c7616c11f6176f167fcf5d1bff33a777b /Source/Android | |
| parent | 1ef75021b6357762767515915eda1f3d3b4e5036 (diff) | |
| parent | 60ca0626dfc2a59cc2e8145d0ee5c7d95f7d0ab5 (diff) | |
Merge pull request #14230 from Sintendo/file-search
Common/FileSearch: Refactor DoFileSearch
Diffstat (limited to 'Source/Android')
| -rw-r--r-- | Source/Android/jni/AndroidCommon/AndroidCommon.cpp | 13 | ||||
| -rw-r--r-- | Source/Android/jni/AndroidCommon/AndroidCommon.h | 23 | ||||
| -rw-r--r-- | Source/Android/jni/Config/PostProcessing.cpp | 6 | ||||
| -rw-r--r-- | Source/Android/jni/GameList/GameFileCache.cpp | 10 |
4 files changed, 35 insertions, 17 deletions
diff --git a/Source/Android/jni/AndroidCommon/AndroidCommon.cpp b/Source/Android/jni/AndroidCommon/AndroidCommon.cpp index a976d573b8..029b64aa36 100644 --- a/Source/Android/jni/AndroidCommon/AndroidCommon.cpp +++ b/Source/Android/jni/AndroidCommon/AndroidCommon.cpp @@ -5,6 +5,7 @@ #include <algorithm> #include <ios> +#include <span> #include <string> #include <string_view> #include <vector> @@ -49,9 +50,13 @@ std::vector<std::string> JStringArrayToVector(JNIEnv* env, jobjectArray array) return result; } -jobjectArray VectorToJStringArray(JNIEnv* env, const std::vector<std::string>& vector) +jobjectArray SpanToJStringArray(JNIEnv* env, std::span<const std::string_view> span) { - return VectorToJObjectArray(env, vector, IDCache::GetStringClass(), ToJString); + return SpanToJObjectArray(env, span, IDCache::GetStringClass(), ToJString); +} +jobjectArray SpanToJStringArray(JNIEnv* env, std::span<const std::string> span) +{ + return SpanToJObjectArray(env, span, IDCache::GetStringClass(), ToJString); } bool IsPathAndroidContent(std::string_view uri) @@ -193,13 +198,13 @@ std::vector<std::string> GetAndroidContentChildNames(std::string_view uri) } std::vector<std::string> DoFileSearchAndroidContent(std::string_view directory, - const std::vector<std::string>& extensions, + std::span<const std::string_view> extensions, bool recursive) { JNIEnv* env = IDCache::GetEnvForThread(); jstring j_directory = ToJString(env, directory); - jobjectArray j_extensions = VectorToJStringArray(env, extensions); + jobjectArray j_extensions = SpanToJStringArray(env, extensions); jobjectArray j_result = reinterpret_cast<jobjectArray>(env->CallStaticObjectMethod( IDCache::GetContentHandlerClass(), IDCache::GetContentHandlerDoFileSearch(), j_directory, diff --git a/Source/Android/jni/AndroidCommon/AndroidCommon.h b/Source/Android/jni/AndroidCommon/AndroidCommon.h index cc86795418..e04180ef20 100644 --- a/Source/Android/jni/AndroidCommon/AndroidCommon.h +++ b/Source/Android/jni/AndroidCommon/AndroidCommon.h @@ -4,6 +4,7 @@ #pragma once #include <ios> +#include <span> #include <string> #include <string_view> #include <vector> @@ -14,22 +15,30 @@ std::string GetJString(JNIEnv* env, jstring jstr); jstring ToJString(JNIEnv* env, std::string_view str); std::vector<std::string> JStringArrayToVector(JNIEnv* env, jobjectArray array); -jobjectArray VectorToJStringArray(JNIEnv* env, const std::vector<std::string>& vector); +jobjectArray SpanToJStringArray(JNIEnv* env, std::span<const std::string_view> span); +jobjectArray SpanToJStringArray(JNIEnv* env, std::span<const std::string> span); template <typename T, typename F> -jobjectArray VectorToJObjectArray(JNIEnv* env, const std::vector<T>& vector, jclass clazz, F f) +jobjectArray SpanToJObjectArray(JNIEnv* env, std::span<const T> span, jclass clazz, F f) { - const auto vector_size = static_cast<jsize>(vector.size()); - jobjectArray result = env->NewObjectArray(vector_size, clazz, nullptr); - for (jsize i = 0; i < vector_size; ++i) + const auto span_size = static_cast<jsize>(span.size()); + jobjectArray result = env->NewObjectArray(span_size, clazz, nullptr); + for (jsize i = 0; i < span_size; ++i) { - jobject obj = f(env, vector[i]); + jobject obj = f(env, span[i]); env->SetObjectArrayElement(result, i, obj); env->DeleteLocalRef(obj); } return result; } +template <typename T, typename F> +inline jobjectArray VectorToJObjectArray(JNIEnv* env, const std::vector<T>& vector, jclass clazz, + F f) +{ + return SpanToJObjectArray(env, std::span(vector), clazz, f); +} + // Returns true if the given path should be opened as Android content instead of a normal file. bool IsPathAndroidContent(std::string_view uri); @@ -55,7 +64,7 @@ std::string GetAndroidContentDisplayName(std::string_view uri); std::vector<std::string> GetAndroidContentChildNames(std::string_view uri); std::vector<std::string> DoFileSearchAndroidContent(std::string_view directory, - const std::vector<std::string>& extensions, + std::span<const std::string_view> extensions, bool recursive); int GetNetworkIpAddress(); diff --git a/Source/Android/jni/Config/PostProcessing.cpp b/Source/Android/jni/Config/PostProcessing.cpp index ea1b9d8ad4..5576c2d314 100644 --- a/Source/Android/jni/Config/PostProcessing.cpp +++ b/Source/Android/jni/Config/PostProcessing.cpp @@ -15,20 +15,20 @@ JNIEXPORT jobjectArray JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_PostProcessing_getShaderList(JNIEnv* env, jclass) { - return VectorToJStringArray(env, VideoCommon::PostProcessing::GetShaderList()); + return SpanToJStringArray(env, VideoCommon::PostProcessing::GetShaderList()); } JNIEXPORT jobjectArray JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_PostProcessing_getAnaglyphShaderList( JNIEnv* env, jclass) { - return VectorToJStringArray(env, VideoCommon::PostProcessing::GetAnaglyphShaderList()); + return SpanToJStringArray(env, VideoCommon::PostProcessing::GetAnaglyphShaderList()); } JNIEXPORT jobjectArray JNICALL Java_org_dolphinemu_dolphinemu_features_settings_model_PostProcessing_getPassiveShaderList( JNIEnv* env, jclass) { - return VectorToJStringArray(env, VideoCommon::PostProcessing::GetPassiveShaderList()); + return SpanToJStringArray(env, VideoCommon::PostProcessing::GetPassiveShaderList()); } } diff --git a/Source/Android/jni/GameList/GameFileCache.cpp b/Source/Android/jni/GameList/GameFileCache.cpp index 27c3b0ef63..c0a78c8cee 100644 --- a/Source/Android/jni/GameList/GameFileCache.cpp +++ b/Source/Android/jni/GameList/GameFileCache.cpp @@ -1,6 +1,8 @@ // Copyright 2018 Dolphin Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include <algorithm> +#include <iterator> #include <memory> #include <vector> @@ -35,14 +37,16 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_finali JNIEXPORT jobjectArray JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_getAllGamePaths( JNIEnv* env, jclass, jobjectArray folder_paths, jboolean recursive_scan) { - return VectorToJStringArray( - env, UICommon::FindAllGamePaths(JStringArrayToVector(env, folder_paths), recursive_scan)); + const std::vector<std::string> paths = JStringArrayToVector(env, folder_paths); + std::vector<std::string_view> path_views; + std::ranges::copy(paths, std::back_inserter(path_views)); + return SpanToJStringArray(env, UICommon::FindAllGamePaths(path_views, recursive_scan)); } JNIEXPORT jobjectArray JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_getIsoPaths(JNIEnv* env, jclass) { - return VectorToJStringArray(env, Config::GetIsoPaths()); + return SpanToJStringArray(env, Config::GetIsoPaths()); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_setIsoPaths( |
