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

Unified Diff: libadblockplus-android/jni/JniFilter.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
« no previous file with comments | « libadblockplus-android/jni/JniFilter.h ('k') | libadblockplus-android/jni/JniFilterChangeCallback.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: libadblockplus-android/jni/JniFilter.cpp
diff --git a/libadblockplus-android/jni/JniFilter.cpp b/libadblockplus-android/jni/JniFilter.cpp
index b3daec386640c00d0805d850f60cbbf2a40c6ce5..e1549b3e7fb709f51ae900ab2d388a51489a9ff7 100644
--- a/libadblockplus-android/jni/JniFilter.cpp
+++ b/libadblockplus-android/jni/JniFilter.cpp
@@ -18,6 +18,24 @@
#include <AdblockPlus.h>
#include "Utils.h"
#include "JniJsValue.h"
+#include "JniFilter.h"
+
+// precached in JNI_OnLoad and released in JNI_OnUnload
+JniGlobalReference<jclass>* filterEnumClass;
+
+void JniFilter_OnLoad(JavaVM* vm, JNIEnv* env, void* reserved)
+{
+ filterEnumClass = new JniGlobalReference<jclass>(env, env->FindClass(PKG("Filter$Type")));
+}
+
+void JniFilter_OnUnload(JavaVM* vm, JNIEnv* env, void* reserved)
+{
+ if (filterEnumClass)
+ {
+ delete filterEnumClass;
+ filterEnumClass = NULL;
+ }
+}
static AdblockPlus::Filter* GetFilterPtr(jlong ptr)
{
@@ -66,10 +84,8 @@ static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr)
break;
}
- JniLocalReference<jclass> enumClass(env, env->FindClass(PKG("Filter$Type")));
- jfieldID enumField = env->GetStaticFieldID(*enumClass, enumName,
- TYP("Filter$Type"));
- return env->GetStaticObjectField(*enumClass, enumField);
+ jfieldID enumField = env->GetStaticFieldID(filterEnumClass->Get(), enumName, TYP("Filter$Type"));
+ return env->GetStaticObjectField(filterEnumClass->Get(), enumField);
}
static jboolean JNICALL JniIsListed(JNIEnv* env, jclass clazz, jlong ptr)
« no previous file with comments | « libadblockplus-android/jni/JniFilter.h ('k') | libadblockplus-android/jni/JniFilterChangeCallback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld