diff options
author | John Reck <jreck@google.com> | 2015-07-10 17:50:10 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-07-10 17:50:12 +0000 |
commit | 525ac80d2dda4ce7a902b67d082ed26d0986f525 (patch) | |
tree | 078b92152180caf1f6f192715f112d9cfff65710 | |
parent | a2c2cc422c47a62b5494c9090b644a8fae8a9037 (diff) | |
parent | 476f7158222e49ec24a5fc08f0bbb33fb8ca10bf (diff) | |
download | frameworks_base-525ac80d2dda4ce7a902b67d082ed26d0986f525.zip frameworks_base-525ac80d2dda4ce7a902b67d082ed26d0986f525.tar.gz frameworks_base-525ac80d2dda4ce7a902b67d082ed26d0986f525.tar.bz2 |
Merge "Create a thread_local cache for textLocale" into mnc-dev
-rw-r--r-- | core/jni/android/graphics/Paint.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp index b9fd65f..bff1885 100644 --- a/core/jni/android/graphics/Paint.cpp +++ b/core/jni/android/graphics/Paint.cpp @@ -74,6 +74,13 @@ static void defaultSettingsForAndroid(Paint* paint) { paint->setTextEncoding(Paint::kGlyphID_TextEncoding); } +struct LocaleCacheEntry { + std::string javaLocale; + std::string languageTag; +}; + +static thread_local LocaleCacheEntry sSingleEntryLocaleCache; + class PaintGlue { public: enum MoveOpt { @@ -399,10 +406,14 @@ public: static void setTextLocale(JNIEnv* env, jobject clazz, jlong objHandle, jstring locale) { Paint* obj = reinterpret_cast<Paint*>(objHandle); ScopedUtfChars localeChars(env, locale); - char langTag[ULOC_FULLNAME_CAPACITY]; - toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, localeChars.c_str()); + if (sSingleEntryLocaleCache.javaLocale != localeChars.c_str()) { + sSingleEntryLocaleCache.javaLocale = localeChars.c_str(); + char langTag[ULOC_FULLNAME_CAPACITY]; + toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, localeChars.c_str()); + sSingleEntryLocaleCache.languageTag = langTag; + } - obj->setTextLocale(langTag); + obj->setTextLocale(sSingleEntryLocaleCache.languageTag); } static jboolean isElegantTextHeight(JNIEnv* env, jobject paint) { |