From: Kenny Root Date: Tue, 23 Feb 2010 06:36:26 +0000 (-0800) Subject: Use UTF-8 strings to avoid duplicate caching, part 1 X-Git-Url: https://git.saurik.com/android/aapt.git/commitdiff_plain/054e9517d9586fb31af8d3bb8dcffc0b76e06ac4 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 --- 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); } }