diff options
| author | 2020-07-14 12:23:21 -0700 | |
|---|---|---|
| committer | 2020-07-15 16:35:00 +0000 | |
| commit | 44c4994dca5e968a423dc3510d2e15d9f4d92f8d (patch) | |
| tree | 1f091794cc983838eeebe43f3f12879f8dfb9f72 | |
| parent | 76539712ca0b3bdc149c188a27add62f9bdfa04c (diff) | |
Don't clone the locale redundantly in Configuration.setTo()
When updating an existing Configuration instance, don't create a new
clone of the pattern's embedded Locale unless it is materially different
from the existing instance's own.
Bug: 161264248
Test: boot & run
Test: atest AppConfigurationTests
Test: atest ConfigChangeTests
Test: atest LocaleListTest
Change-Id: I5dc0598b89305c488ba50c1774ecdabf939a6ccc
| -rw-r--r-- | core/java/android/content/res/Configuration.java | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java index 6a9e0aa047d1..9480d369065d 100644 --- a/core/java/android/content/res/Configuration.java +++ b/core/java/android/content/res/Configuration.java @@ -45,7 +45,6 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.TestApi; -import android.app.UiModeManager; import android.app.WindowConfiguration; import android.compat.annotation.UnsupportedAppUsage; import android.content.LocaleProto; @@ -928,7 +927,13 @@ public final class Configuration implements Parcelable, Comparable<Configuration fontScale = o.fontScale; mcc = o.mcc; mnc = o.mnc; - locale = o.locale == null ? null : (Locale) o.locale.clone(); + if (o.locale == null) { + locale = null; + } else if (!o.locale.equals(locale)) { + // Only clone a new Locale instance if we need to: the clone() is + // both CPU and GC intensive. + locale = (Locale) o.locale.clone(); + } o.fixUpLocaleList(); mLocaleList = o.mLocaleList; userSetLocale = o.userSetLocale; @@ -1624,7 +1629,10 @@ public final class Configuration implements Parcelable, Comparable<Configuration if ((mask & ActivityInfo.CONFIG_LOCALE) != 0) { mLocaleList = delta.mLocaleList; if (!mLocaleList.isEmpty()) { - locale = (Locale) delta.locale.clone(); + if (!delta.locale.equals(locale)) { + // Don't churn a new Locale clone unless we're actually changing it + locale = (Locale) delta.locale.clone(); + } } } if ((mask & ActivityInfo.CONFIG_LAYOUT_DIRECTION) != 0) { |