New issue
Advanced search Search tips

Issue 921104 link

Starred by 1 user

Issue metadata

Status: Available
Owner: ----
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Bug



Sign in to add a comment

Java Style Guide: Recommend ArrayMap / ArraySet

Project Member Reported by agrieve@chromium.org, Jan 11

Issue description

ArrayMap / ArraySet are recommended by Android as more efficient than HashMap / HashSet.

They are in the support library:
https://developer.android.com/reference/android/support/v4/util/ArrayMap
https://developer.android.com/reference/android/support/v4/util/ArraySet

ArrayMap was added to Android in api 19 (Android L):
https://developer.android.com/reference/android/util/ArrayMap

ArraySet was added to Android in api 23 (Android N):
https://developer.android.com/reference/android/util/ArraySet

We should:

1) Suggest that we add some style guide text encouraging their use.
2) Write an errorprone check to encourage their use + mass-suppression / conversion.
3) Write a compat shim so that we use support library versions for old apks and OS ones for new apks. e.g.:

Map<K, V> org.chromium.base.CollectionUtil.newArrayMap() {
  if (Build.VERSION >= 19) {
     return new android.util.ArrayMap();
  } else {
     return new android.support.v4.util.ArrayMap();
  }
}


The advantage of preferring the OS version for newer APIs is that it will let proguard remove the support library one, and the code for the map should already be loaded as part of the system zygote.
 
Status: Untriaged (was: Available)
Available, but no owner or component? Please find a component, as no one will ever find this without one.
Labels: QuickFix
Status: Available (was: Untriaged)

Sign in to add a comment