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

Side by Side Diff: libadblockplus-android/jni/Utils.h

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/JniWebRequest.cpp ('k') | libadblockplus-android/jni/Utils.cpp » ('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 13 matching lines...) Expand all
24 #include <stdexcept> 24 #include <stdexcept>
25 #include <memory> 25 #include <memory>
26 26
27 #include <AdblockPlus.h> 27 #include <AdblockPlus.h>
28 28
29 #define PKG(x) "org/adblockplus/libadblockplus/" x 29 #define PKG(x) "org/adblockplus/libadblockplus/" x
30 #define TYP(x) "L" PKG(x) ";" 30 #define TYP(x) "L" PKG(x) ";"
31 31
32 #define ABP_JNI_VERSION JNI_VERSION_1_6 32 #define ABP_JNI_VERSION JNI_VERSION_1_6
33 33
34 void JniUtils_OnLoad(JavaVM* vm, JNIEnv* env, void* reserved);
35
36 void JniUtils_OnUnload(JavaVM* vm, JNIEnv* env, void* reserved);
37
34 void JniThrowException(JNIEnv* env, const std::string& message); 38 void JniThrowException(JNIEnv* env, const std::string& message);
35 39
36 void JniThrowException(JNIEnv* env, const std::exception& e); 40 void JniThrowException(JNIEnv* env, const std::exception& e);
37 41
38 void JniThrowException(JNIEnv* env); 42 void JniThrowException(JNIEnv* env);
39 43
40 class JNIEnvAcquire; 44 class JNIEnvAcquire;
41 45
42 /** 46 /**
43 * This class is _NOT_ thread safe! 47 * This class is _NOT_ thread safe!
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // dynamic_casts to shared_ptr<T: JsValue> ... also as the same inheritance is m irrored on the Java 146 // dynamic_casts to shared_ptr<T: JsValue> ... also as the same inheritance is m irrored on the Java
143 // side (and Java will throw a class cast exception on error) this shouldn't be an issue (TM) 147 // side (and Java will throw a class cast exception on error) this shouldn't be an issue (TM)
144 template<typename T> 148 template<typename T>
145 inline T* JniLongToTypePtr(jlong value) 149 inline T* JniLongToTypePtr(jlong value)
146 { 150 {
147 return reinterpret_cast<T*>((size_t)value); 151 return reinterpret_cast<T*>((size_t)value);
148 } 152 }
149 153
150 std::string JniJavaToStdString(JNIEnv* env, jstring str); 154 std::string JniJavaToStdString(JNIEnv* env, jstring str);
151 155
156 jmethodID JniGetAddToListMethod(JNIEnv* env, jobject list);
157
158 void JniAddObjectToList(JNIEnv* env, jobject list, jmethodID addMethod, jobject value);
159
152 void JniAddObjectToList(JNIEnv* env, jobject list, jobject value); 160 void JniAddObjectToList(JNIEnv* env, jobject list, jobject value);
153 161
154 inline std::string JniGetStringField(JNIEnv* env, jclass clazz, jobject jObj, co nst char* name) 162 inline std::string JniGetStringField(JNIEnv* env, jclass clazz, jobject jObj, co nst char* name)
155 { 163 {
156 return JniJavaToStdString(env, reinterpret_cast<jstring>(env->GetObjectField(j Obj, env->GetFieldID(clazz, name, "Ljava/lang/String;")))); 164 return JniJavaToStdString(env, reinterpret_cast<jstring>(env->GetObjectField(j Obj, env->GetFieldID(clazz, name, "Ljava/lang/String;"))));
157 } 165 }
158 166
159 inline bool JniGetBooleanField(JNIEnv* env, jclass clazz, jobject jObj, const ch ar* name) 167 inline bool JniGetBooleanField(JNIEnv* env, jclass clazz, jobject jObj, const ch ar* name)
160 { 168 {
161 return env->GetBooleanField(jObj, env->GetFieldID(clazz, name, "Z")) == JNI_TR UE; 169 return env->GetBooleanField(jObj, env->GetFieldID(clazz, name, "Z")) == JNI_TR UE;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 JniThrowException(jEnv, except); \ 210 JniThrowException(jEnv, except); \
203 return retVal; \ 211 return retVal; \
204 } \ 212 } \
205 catch (...) \ 213 catch (...) \
206 { \ 214 { \
207 JniThrowException(jEnv); \ 215 JniThrowException(jEnv); \
208 return retVal; \ 216 return retVal; \
209 } 217 }
210 218
211 #endif 219 #endif
OLDNEW
« no previous file with comments | « libadblockplus-android/jni/JniWebRequest.cpp ('k') | libadblockplus-android/jni/Utils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld