jni_helpers: Optimize IsNull()

The current implementation is unnecessary expensive - we create a local reference frame for creating new Java objects and then create a new local reference. It's cheaper to just do jni->IsSameObject(obj, nullptr).

R=perkj@webrtc.org

Review URL: https://codereview.webrtc.org/1741723002 .

Cr-Commit-Position: refs/heads/master@{#11825}
This commit is contained in:
Magnus Jedvert
2016-03-01 10:10:01 +01:00
parent dc29780722
commit ffdd41ecf2
2 changed files with 2 additions and 6 deletions

View File

@ -202,11 +202,8 @@ bool GetBooleanField(JNIEnv* jni, jobject object, jfieldID id) {
return b;
}
// Java references to "null" can only be distinguished as such in C++ by
// creating a local reference, so this helper wraps that logic.
bool IsNull(JNIEnv* jni, jobject obj) {
ScopedLocalRefFrame local_ref_frame(jni);
return jni->NewLocalRef(obj) == NULL;
return jni->IsSameObject(obj, nullptr);
}
// Given a UTF-8 encoded |native| string return a new (UTF-16) jstring.

View File

@ -72,8 +72,7 @@ jint GetIntField(JNIEnv* jni, jobject object, jfieldID id);
bool GetBooleanField(JNIEnv* jni, jobject object, jfieldID id);
// Java references to "null" can only be distinguished as such in C++ by
// creating a local reference, so this helper wraps that logic.
// Returns true if |obj| == null in Java.
bool IsNull(JNIEnv* jni, jobject obj);
// Given a UTF-8 encoded |native| string return a new (UTF-16) jstring.