Avoid unnecessary FindClass("java/lang/String").
Use previously retrieved global reference instead.
Check for NULL after creating the global reference.
Change-Id: I21670d2ef0f63ddb5801dd21e7e56359e5519479
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp
index d422951..89dc70d 100644
--- a/core/jni/android_util_AssetManager.cpp
+++ b/core/jni/android_util_AssetManager.cpp
@@ -293,17 +293,10 @@
return NULL;
}
- jclass cls = env->FindClass("java/lang/String");
- LOG_FATAL_IF(cls == NULL, "No string class?!?");
- if (cls == NULL) {
- delete dir;
- return NULL;
- }
-
size_t N = dir->getFileCount();
jobjectArray array = env->NewObjectArray(dir->getFileCount(),
- cls, NULL);
+ g_stringClass, NULL);
if (array == NULL) {
delete dir;
return NULL;
@@ -1455,19 +1448,13 @@
}
const ResTable& res(am->getResources());
- jclass cls = env->FindClass("java/lang/String");
- LOG_FATAL_IF(cls == NULL, "No string class?!?");
- if (cls == NULL) {
- return NULL;
- }
-
const ResTable::bag_entry* startOfBag;
const ssize_t N = res.lockBag(arrayResId, &startOfBag);
if (N < 0) {
return NULL;
}
- jobjectArray array = env->NewObjectArray(N, cls, NULL);
+ jobjectArray array = env->NewObjectArray(N, g_stringClass, NULL);
if (env->ExceptionCheck()) {
res.unlockBag(startOfBag);
return NULL;
@@ -1764,6 +1751,7 @@
jclass stringClass = env->FindClass("java/lang/String");
LOG_FATAL_IF(stringClass == NULL, "Unable to find class java/lang/String");
g_stringClass = (jclass)env->NewGlobalRef(stringClass);
+ LOG_FATAL_IF(g_stringClass == NULL, "Unable to create global reference for class java/lang/String");
return AndroidRuntime::registerNativeMethods(env,
"android/content/res/AssetManager", gAssetManagerMethods, NELEM(gAssetManagerMethods));