diff --git a/Source/Android/jni/AndroidCommon/IDCache.cpp b/Source/Android/jni/AndroidCommon/IDCache.cpp index 25a051ff2d..e4cacaa462 100644 --- a/Source/Android/jni/AndroidCommon/IDCache.cpp +++ b/Source/Android/jni/AndroidCommon/IDCache.cpp @@ -32,6 +32,10 @@ static jclass s_linked_hash_map_class; static jmethodID s_linked_hash_map_init; static jmethodID s_linked_hash_map_put; +static jclass s_hash_map_class; +static jmethodID s_hash_map_init; +static jmethodID s_hash_map_put; + static jclass s_ini_file_class; static jfieldID s_ini_file_pointer; static jclass s_ini_file_section_class; @@ -221,6 +225,21 @@ jmethodID GetLinkedHashMapPut() return s_linked_hash_map_put; } +jclass GetHashMapClass() +{ + return s_hash_map_class; +} + +jmethodID GetHashMapInit() +{ + return s_hash_map_init; +} + +jmethodID GetHashMapPut() +{ + return s_hash_map_put; +} + jclass GetIniFileClass() { return s_ini_file_class; @@ -575,12 +594,19 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) ini_file_section_class, "", "(Lorg/dolphinemu/dolphinemu/utils/IniFile;J)V"); env->DeleteLocalRef(ini_file_section_class); - const jclass map_class = env->FindClass("java/util/LinkedHashMap"); - s_linked_hash_map_class = reinterpret_cast(env->NewGlobalRef(map_class)); + const jclass linked_hash_map_class = env->FindClass("java/util/LinkedHashMap"); + s_linked_hash_map_class = reinterpret_cast(env->NewGlobalRef(linked_hash_map_class)); s_linked_hash_map_init = env->GetMethodID(s_linked_hash_map_class, "", "(I)V"); s_linked_hash_map_put = env->GetMethodID( s_linked_hash_map_class, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); - env->DeleteLocalRef(map_class); + env->DeleteLocalRef(linked_hash_map_class); + + const jclass hash_map_class = env->FindClass("java/util/HashMap"); + s_hash_map_class = reinterpret_cast(env->NewGlobalRef(hash_map_class)); + s_hash_map_init = env->GetMethodID(s_hash_map_class, "", "(I)V"); + s_hash_map_put = env->GetMethodID(s_hash_map_class, "put", + "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); + env->DeleteLocalRef(hash_map_class); const jclass compress_cb_class = env->FindClass("org/dolphinemu/dolphinemu/utils/CompressCallback"); @@ -741,6 +767,7 @@ JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved) env->DeleteGlobalRef(s_game_file_cache_class); env->DeleteGlobalRef(s_analytics_class); env->DeleteGlobalRef(s_linked_hash_map_class); + env->DeleteGlobalRef(s_hash_map_class); env->DeleteGlobalRef(s_ini_file_class); env->DeleteGlobalRef(s_ini_file_section_class); env->DeleteGlobalRef(s_compress_cb_class); diff --git a/Source/Android/jni/AndroidCommon/IDCache.h b/Source/Android/jni/AndroidCommon/IDCache.h index 967703b9b0..dc8f4d51a1 100644 --- a/Source/Android/jni/AndroidCommon/IDCache.h +++ b/Source/Android/jni/AndroidCommon/IDCache.h @@ -32,6 +32,10 @@ jclass GetLinkedHashMapClass(); jmethodID GetLinkedHashMapInit(); jmethodID GetLinkedHashMapPut(); +jclass GetHashMapClass(); +jmethodID GetHashMapInit(); +jmethodID GetHashMapPut(); + jclass GetIniFileClass(); jfieldID GetIniFilePointer(); jclass GetIniFileSectionClass(); diff --git a/Source/Android/jni/InfinityConfig.cpp b/Source/Android/jni/InfinityConfig.cpp index cd96dfc74c..7be0402769 100644 --- a/Source/Android/jni/InfinityConfig.cpp +++ b/Source/Android/jni/InfinityConfig.cpp @@ -6,6 +6,7 @@ #include #include "AndroidCommon/AndroidCommon.h" +#include "AndroidCommon/IDCache.h" #include "Core/IOS/USB/Emulated/Infinity.h" #include "Core/System.h" @@ -20,9 +21,6 @@ Java_org_dolphinemu_dolphinemu_features_infinitybase_InfinityConfig_getFigureMap jobject hash_map_obj = env->NewObject(IDCache::GetHashMapClass(), IDCache::GetHashMapInit(), system.GetInfinityBase().GetFigureList().size()); - jmethodID hash_map_put = env->GetMethodID( - hash_map_class, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); - jclass long_class = env->FindClass("java/lang/Long"); jmethodID long_init = env->GetMethodID(long_class, "", "(J)V"); @@ -47,9 +45,6 @@ Java_org_dolphinemu_dolphinemu_features_infinitybase_InfinityConfig_getInverseFi jobject hash_map_obj = env->NewObject(IDCache::GetHashMapClass(), IDCache::GetHashMapInit(), system.GetInfinityBase().GetFigureList().size()); - jmethodID hash_map_put = env->GetMethodID( - hash_map_class, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); - jclass long_class = env->FindClass("java/lang/Long"); jmethodID long_init = env->GetMethodID(long_class, "", "(J)V"); diff --git a/Source/Android/jni/SkylanderConfig.cpp b/Source/Android/jni/SkylanderConfig.cpp index 4d6c0d1375..306b574938 100644 --- a/Source/Android/jni/SkylanderConfig.cpp +++ b/Source/Android/jni/SkylanderConfig.cpp @@ -6,6 +6,7 @@ #include #include "AndroidCommon/AndroidCommon.h" +#include "AndroidCommon/IDCache.h" #include "Core/IOS/USB/Emulated/Skylander.h" #include "Core/System.h" @@ -15,12 +16,8 @@ JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_features_skylanders_SkylanderConfig_getSkylanderMap(JNIEnv* env, jclass clazz) { - jclass hash_map_class = env->FindClass("java/util/HashMap"); - jmethodID hash_map_init = env->GetMethodID(hash_map_class, "", "(I)V"); - jobject hash_map_obj = env->NewObject(hash_map_class, hash_map_init, + jobject hash_map_obj = env->NewObject(IDCache::GetHashMapClass(), IDCache::GetHashMapInit(), static_cast(IOS::HLE::USB::list_skylanders.size())); - jmethodID hash_map_put = env->GetMethodID( - hash_map_class, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); jclass skylander_class = env->FindClass("org/dolphinemu/dolphinemu/features/skylanders/model/SkylanderPair"); @@ -32,7 +29,8 @@ Java_org_dolphinemu_dolphinemu_features_skylanders_SkylanderConfig_getSkylanderM const std::string& name = it.second; jobject skylander_obj = env->NewObject(skylander_class, skylander_init, it.first.first, it.first.second); - env->CallObjectMethod(hash_map_obj, hash_map_put, skylander_obj, ToJString(env, name)); + env->CallObjectMethod(hash_map_obj, IDCache::GetHashMapPut(), skylander_obj, + ToJString(env, name)); env->DeleteLocalRef(skylander_obj); } @@ -43,12 +41,8 @@ JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_features_skylanders_SkylanderConfig_getInverseSkylanderMap( JNIEnv* env, jclass clazz) { - jclass hash_map_class = env->FindClass("java/util/HashMap"); - jmethodID hash_map_init = env->GetMethodID(hash_map_class, "", "(I)V"); - jobject hash_map_obj = env->NewObject(hash_map_class, hash_map_init, + jobject hash_map_obj = env->NewObject(IDCache::GetHashMapClass(), IDCache::GetHashMapInit(), static_cast(IOS::HLE::USB::list_skylanders.size())); - jmethodID hash_map_put = env->GetMethodID( - hash_map_class, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); jclass skylander_class = env->FindClass("org/dolphinemu/dolphinemu/features/skylanders/model/SkylanderPair"); @@ -60,7 +54,8 @@ Java_org_dolphinemu_dolphinemu_features_skylanders_SkylanderConfig_getInverseSky const std::string& name = it.second; jobject skylander_obj = env->NewObject(skylander_class, skylander_init, it.first.first, it.first.second); - env->CallObjectMethod(hash_map_obj, hash_map_put, ToJString(env, name), skylander_obj); + env->CallObjectMethod(hash_map_obj, IDCache::GetHashMapPut(), ToJString(env, name), + skylander_obj); env->DeleteLocalRef(skylander_obj); }