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}
diff --git a/webrtc/api/java/jni/jni_helpers.cc b/webrtc/api/java/jni/jni_helpers.cc
index cd15014..32092e6 100644
--- a/webrtc/api/java/jni/jni_helpers.cc
+++ b/webrtc/api/java/jni/jni_helpers.cc
@@ -202,11 +202,8 @@
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.
diff --git a/webrtc/api/java/jni/jni_helpers.h b/webrtc/api/java/jni/jni_helpers.h
index 05a9565..87c5ca4 100644
--- a/webrtc/api/java/jni/jni_helpers.h
+++ b/webrtc/api/java/jni/jni_helpers.h
@@ -72,8 +72,7 @@
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.