From 054e9517d9586fb31af8d3bb8dcffc0b76e06ac4 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Mon, 22 Feb 2010 22:36:26 -0800 Subject: [PATCH] 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 --- StringPool.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/StringPool.cpp b/StringPool.cpp index 51afc0a..a09cec0 100644 --- a/StringPool.cpp +++ b/StringPool.cpp @@ -25,8 +25,12 @@ void printStringPool(const ResStringPool* pool) const size_t NS = pool->size(); for (size_t s=0; sstringAt(s, &len)).string()); + const char *str = (const char*)pool->string8At(s, &len); + if (str == NULL) { + str = String8(pool->stringAt(s, &len)).string(); + } + + printf("String #%ld: %s\n", s, str); } } -- 2.45.2