Java Style Guide: Recommend ArrayMap / ArraySet |
|||
Issue descriptionArrayMap / 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.
,
Jan 14
,
Jan 14
|
|||
►
Sign in to add a comment |
|||
Comment 1 by benhenry@google.com
, Jan 11