summaryrefslogtreecommitdiffstats
path: root/core/jni/android_util_StringBlock.cpp
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2010-02-22 22:36:26 -0800
committerKenny Root <kroot@google.com>2010-02-23 10:02:20 -0800
commit780d2a1b714724d85227141c76b3c64f543f00b4 (patch)
tree3bd5411acce1ae663e4509c812b3aaa6100c6a41 /core/jni/android_util_StringBlock.cpp
parentcfe79e9220c996ed9f60fbc00eebb23e7faba2f0 (diff)
downloadframeworks_base-780d2a1b714724d85227141c76b3c64f543f00b4.zip
frameworks_base-780d2a1b714724d85227141c76b3c64f543f00b4.tar.gz
frameworks_base-780d2a1b714724d85227141c76b3c64f543f00b4.tar.bz2
Use UTF-8 strings to avoid duplicate caching, part 1
StringBlock instances containing UTF-8 strings use a cache to convert into UTF-16, but using that cache and then using a JNI call to NewString causes the UTF-8 string as well as two copies of the UTF-16 string to be held in memory. Getting the UTF-8 string directly from the StringPool eliminates one copy of the UTF-16 string being held in memory. This is part 1. Part 2 will include ResXMLParser optimizations. Change-Id: Ibd4509a485db746d59cd4b9501f544877139276c
Diffstat (limited to 'core/jni/android_util_StringBlock.cpp')
-rw-r--r--core/jni/android_util_StringBlock.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/core/jni/android_util_StringBlock.cpp b/core/jni/android_util_StringBlock.cpp
index ffb271c..641fbce 100644
--- a/core/jni/android_util_StringBlock.cpp
+++ b/core/jni/android_util_StringBlock.cpp
@@ -89,6 +89,11 @@ static jstring android_content_StringBlock_nativeGetString(JNIEnv* env, jobject
}
size_t len;
+ const char* str8 = osb->string8At(idx, &len);
+ if (str8 != NULL) {
+ return env->NewStringUTF(str8);
+ }
+
const char16_t* str = osb->stringAt(idx, &len);
if (str == NULL) {
doThrow(env, "java/lang/IndexOutOfBoundsException");