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

Side by Side Diff: libadblockplus-android/jni/JniFilterChangeCallback.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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « libadblockplus-android/jni/JniFilter.cpp ('k') | libadblockplus-android/jni/JniJsValue.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 15 matching lines...) Expand all
26 CATCH_THROW_AND_RETURN(env, 0) 26 CATCH_THROW_AND_RETURN(env, 0)
27 } 27 }
28 28
29 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 29 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
30 { 30 {
31 delete JniLongToTypePtr<JniFilterChangeCallback>(ptr); 31 delete JniLongToTypePtr<JniFilterChangeCallback>(ptr);
32 } 32 }
33 33
34 JniFilterChangeCallback::JniFilterChangeCallback(JNIEnv* env, 34 JniFilterChangeCallback::JniFilterChangeCallback(JNIEnv* env,
35 jobject callbackObject) 35 jobject callbackObject)
36 : JniCallbackBase(env, callbackObject), jsValueClass( 36 : JniCallbackBase(env, callbackObject)
37 new JniGlobalReference<jclass>(env, env->FindClass(PKG("JsValue"))))
38 { 37 {
39 } 38 }
40 39
41 void JniFilterChangeCallback::Callback(const std::string& arg, 40 void JniFilterChangeCallback::Callback(const std::string& arg,
42 const AdblockPlus::JsValuePtr jsValue) 41 const AdblockPlus::JsValuePtr jsValue)
43 { 42 {
44 JNIEnvAcquire env(GetJavaVM()); 43 JNIEnvAcquire env(GetJavaVM());
45 44
46 jmethodID method = env->GetMethodID( 45 jmethodID method = env->GetMethodID(
47 *JniLocalReference<jclass>(*env, 46 *JniLocalReference<jclass>(*env,
48 env->GetObjectClass(GetCallbackObject())), 47 env->GetObjectClass(GetCallbackObject())),
49 "filterChangeCallback", "(Ljava/lang/String;" TYP("JsValue") ")V"); 48 "filterChangeCallback", "(Ljava/lang/String;" TYP("JsValue") ")V");
50 49
51 if (method) 50 if (method)
52 { 51 {
53 JniLocalReference<jstring> jArg(*env, env->NewStringUTF(arg.c_str())); 52 JniLocalReference<jstring> jArg(*env, env->NewStringUTF(arg.c_str()));
54 JniLocalReference<jobject> jJsValue(*env, 53 JniLocalReference<jobject> jJsValue(*env, NewJniJsValue(*env, jsValue, GetJs ValueClass()));
55 NewJniJsValue(*env, jsValue, jsValueClass->Get()));
56 env->CallVoidMethod(GetCallbackObject(), method, *jArg, *jJsValue); 54 env->CallVoidMethod(GetCallbackObject(), method, *jArg, *jJsValue);
57 } 55 }
58 56
59 CheckAndLogJavaException(*env); 57 CheckAndLogJavaException(*env);
60 } 58 }
61 59
62 static JNINativeMethod methods[] = 60 static JNINativeMethod methods[] =
63 { 61 {
64 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, 62 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor },
65 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 63 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
66 }; 64 };
67 65
68 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterChan geCallback_registerNatives(JNIEnv *env, jclass clazz) 66 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterChan geCallback_registerNatives(JNIEnv *env, jclass clazz)
69 { 67 {
70 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 68 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
71 } 69 }
OLDNEW
« no previous file with comments | « libadblockplus-android/jni/JniFilter.cpp ('k') | libadblockplus-android/jni/JniJsValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld