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:
@ -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.
|
||||
|
||||
@ -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.
|
||||
|
||||
Reference in New Issue
Block a user