From 0c13c67158c5c1ca00b659a05f95de18a03fa57b Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Thu, 11 Feb 2021 16:14:37 -0800 Subject: [PATCH] Remove unnecessary calls to JNIEnv::GetArrayLength Replace repeated calls to JNIEnv::GetArrayLength operating on the same array with a cached value obtained once and then reused. Bug: 165832481 Signed-off-by: Suren Baghdasaryan Change-Id: Id85f887a9a4dc8eeacbb047beca7ced49853484e --- core/jni/android_os_Debug.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp index b5373f7347ae8..c4caef2ecdb9d 100644 --- a/core/jni/android_os_Debug.cpp +++ b/core/jni/android_os_Debug.cpp @@ -520,14 +520,15 @@ static jlong android_os_Debug_getPssPid(JNIEnv *env, jobject clazz, jint pid, } if (outUssSwapPssRss != NULL) { - if (env->GetArrayLength(outUssSwapPssRss) >= 1) { + int outLen = env->GetArrayLength(outUssSwapPssRss); + if (outLen >= 1) { jlong* outUssSwapPssRssArray = env->GetLongArrayElements(outUssSwapPssRss, 0); if (outUssSwapPssRssArray != NULL) { outUssSwapPssRssArray[0] = uss; - if (env->GetArrayLength(outUssSwapPssRss) >= 2) { + if (outLen >= 2) { outUssSwapPssRssArray[1] = swapPss; } - if (env->GetArrayLength(outUssSwapPssRss) >= 3) { + if (outLen >= 3) { outUssSwapPssRssArray[2] = rss; } } @@ -536,17 +537,18 @@ static jlong android_os_Debug_getPssPid(JNIEnv *env, jobject clazz, jint pid, } if (outMemtrack != NULL) { - if (env->GetArrayLength(outMemtrack) >= 1) { + int outLen = env->GetArrayLength(outMemtrack); + if (outLen >= 1) { jlong* outMemtrackArray = env->GetLongArrayElements(outMemtrack, 0); if (outMemtrackArray != NULL) { outMemtrackArray[0] = memtrack; - if (env->GetArrayLength(outMemtrack) >= 2) { + if (outLen >= 2) { outMemtrackArray[1] = graphics_mem.graphics; } - if (env->GetArrayLength(outMemtrack) >= 3) { + if (outLen >= 3) { outMemtrackArray[2] = graphics_mem.gl; } - if (env->GetArrayLength(outMemtrack) >= 4) { + if (outLen >= 4) { outMemtrackArray[3] = graphics_mem.other; } }