Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: libadblockplus-android/jni/JniJsValue.cpp

Issue 29345737: Issue 4146 - Fix failing UpdateCheckTest.testApplicationUpdateAvailable test in libadblockplus-andr… (Closed)
Patch Set: moved entry points to JniLibrary.cpp Created Sept. 14, 2016, 7:38 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: libadblockplus-android/jni/JniJsValue.cpp
diff --git a/libadblockplus-android/jni/JniJsValue.cpp b/libadblockplus-android/jni/JniJsValue.cpp
index 86af61459baaeaa468e7a832230b60fc35cb98bb..af53e4b1025472012c3e118747d8019a0511381b 100644
--- a/libadblockplus-android/jni/JniJsValue.cpp
+++ b/libadblockplus-android/jni/JniJsValue.cpp
@@ -19,6 +19,19 @@
#include "Utils.h"
#include "JniJsValue.h"
+// precached in JNI_OnLoad and released in JNI_OnUnload
+jclass globalJsValueClass;
+jmethodID jsValueClassCtor;
+
+void JniJsValue_OnLoad(JavaVM* vm, JNIEnv* env, void* reserved)
+{
+ // precache for performance and avoid attaching threads
+ jclass localJsValueClass = env->FindClass(PKG("JsValue"));
+ globalJsValueClass = (jclass)env->NewGlobalRef(localJsValueClass);
+ jsValueClassCtor = env->GetMethodID(globalJsValueClass, "<init>", "(J)V");
+ env->DeleteLocalRef(localJsValueClass);
+}
+
static jboolean JNICALL JniIsUndefined(JNIEnv* env, jclass clazz, jlong ptr)
{
try
@@ -150,17 +163,8 @@ jobject NewJniJsValue(JNIEnv* env, const AdblockPlus::JsValuePtr& jsValue, jclas
return 0;
}
- jclass clazz = jsValueClass ? jsValueClass : env->FindClass(PKG("JsValue"));
- jmethodID ctor = env->GetMethodID(clazz, "<init>", "(J)V");
jlong ptr = JniPtrToLong(new AdblockPlus::JsValuePtr(jsValue));
- jobject ret = env->NewObject(clazz, ctor, ptr);
-
- if (!jsValueClass)
- {
- env->DeleteLocalRef(clazz);
- }
-
- return ret;
+ return env->NewObject(globalJsValueClass, jsValueClassCtor, ptr);
}
AdblockPlus::JsValue* JniGetJsValue(jlong ptr)
@@ -219,3 +223,11 @@ extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsValue_re
{
env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
}
+
+void JniJsValue_OnUnload(JavaVM *vm, JNIEnv *env, void *reserved)
Felix Dahlke 2016/09/15 13:01:19 Nit: Asterisk should be next to the type according
anton 2016/09/15 13:18:11 Acknowledged.
+{
+ if (globalJsValueClass)
+ {
+ env->DeleteGlobalRef(globalJsValueClass);
+ }
+}

Powered by Google App Engine
This is Rietveld