From ffdd41ecf2180c4f52f003915a4bd514bb5e5736 Mon Sep 17 00:00:00 2001 From: Magnus Jedvert Date: Tue, 1 Mar 2016 10:10:01 +0100 Subject: [PATCH] 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} --- webrtc/api/java/jni/jni_helpers.cc | 5 +---- webrtc/api/java/jni/jni_helpers.h | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/webrtc/api/java/jni/jni_helpers.cc b/webrtc/api/java/jni/jni_helpers.cc index cd150142a1..32092e65f8 100644 --- a/webrtc/api/java/jni/jni_helpers.cc +++ b/webrtc/api/java/jni/jni_helpers.cc @@ -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. diff --git a/webrtc/api/java/jni/jni_helpers.h b/webrtc/api/java/jni/jni_helpers.h index 05a956508c..87c5ca48f2 100644 --- a/webrtc/api/java/jni/jni_helpers.h +++ b/webrtc/api/java/jni/jni_helpers.h @@ -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.