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

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

Issue 29354787: Issue 4442 - Cache class and ctors references in JNI_Load/UnLoad (Closed)
Patch Set: reverted to NewTuple Created Nov. 21, 2016, 8:25 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/JniNotification.cpp
diff --git a/libadblockplus-android/jni/JniNotification.cpp b/libadblockplus-android/jni/JniNotification.cpp
index 96d96e88d9cb30e38219a363b800bfb86b29775f..5866ca6c62dfb64534cb4090606c53d3c1cbd97c 100644
--- a/libadblockplus-android/jni/JniNotification.cpp
+++ b/libadblockplus-android/jni/JniNotification.cpp
@@ -15,9 +15,25 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <AdblockPlus.h>
#include "Utils.h"
-#include "JniJsValue.h"
+#include "JniNotification.h"
+
+// precached in JNI_OnLoad and released in JNI_OnUnload
+JniGlobalReference<jclass>* notificationEnumClass;
+
+void JniNotification_OnLoad(JavaVM* vm, JNIEnv* env, void* reserved)
+{
+ notificationEnumClass = new JniGlobalReference<jclass>(env, env->FindClass(PKG("Notification$Type")));
+}
+
+void JniNotification_OnUnload(JavaVM* vm, JNIEnv* env, void* reserved)
+{
+ if (notificationEnumClass)
+ {
+ delete notificationEnumClass;
+ notificationEnumClass = NULL;
+ }
+}
static AdblockPlus::Notification* GetNotificationPtr(jlong ptr)
{
@@ -51,16 +67,12 @@ static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr)
break;
}
- JniLocalReference<jclass> enumClass(
- env,
- env->FindClass(PKG("Notification$Type")));
-
jfieldID enumField = env->GetStaticFieldID(
- *enumClass,
+ notificationEnumClass->Get(),
enumName,
TYP("Notification$Type"));
- return env->GetStaticObjectField(*enumClass, enumField);
+ return env->GetStaticObjectField(notificationEnumClass->Get(), enumField);
}
static jstring JniGetTitle(JNIEnv* env, jclass clazz, jlong ptr)
« no previous file with comments | « libadblockplus-android/jni/JniNotification.h ('k') | libadblockplus-android/jni/JniShowNotificationCallback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld