Commit 4db882f6 authored by Max Kellermann's avatar Max Kellermann

android/LogListener: cache the jmethodID

parent a83bf97b
...@@ -26,6 +26,10 @@ ...@@ -26,6 +26,10 @@
LogListener::LogListener(JNIEnv *env, jobject obj) noexcept LogListener::LogListener(JNIEnv *env, jobject obj) noexcept
:Java::GlobalObject(env, obj) :Java::GlobalObject(env, obj)
{ {
Java::Class cls(env, env->GetObjectClass(Get()));
onLogMethod = env->GetMethodID(cls, "onLog", "(ILjava/lang/String;)V");
assert(onLogMethod);
} }
void void
...@@ -34,18 +38,11 @@ LogListener::OnLog(JNIEnv *env, int priority, ...@@ -34,18 +38,11 @@ LogListener::OnLog(JNIEnv *env, int priority,
{ {
assert(env != nullptr); assert(env != nullptr);
Java::Class cls(env, env->GetObjectClass(Get()));
jmethodID method = env->GetMethodID(cls, "onLog",
"(ILjava/lang/String;)V");
assert(method);
std::va_list args; std::va_list args;
va_start(args, fmt); va_start(args, fmt);
const auto log = FormatStringV(fmt, args); const auto log = FormatStringV(fmt, args);
va_end(args); va_end(args);
env->CallVoidMethod(Get(), method, priority, env->CallVoidMethod(Get(), onLogMethod, priority,
Java::String(env, log.c_str()).Get()); Java::String(env, log.c_str()).Get());
} }
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "java/Object.hxx" #include "java/Object.hxx"
class LogListener : public Java::GlobalObject { class LogListener : public Java::GlobalObject {
jmethodID onLogMethod;
public: public:
LogListener(JNIEnv *env, jobject obj) noexcept; LogListener(JNIEnv *env, jobject obj) noexcept;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment