From d09a4081d6944f7af367ef04683448ce01989000 Mon Sep 17 00:00:00 2001 From: Jan Kowal Date: Thu, 27 Sep 2018 09:54:39 +0200 Subject: [PATCH] Fix for android.hardware.radio.Utils.createIntSet Previous solution was assymetric: writeInt vs readTypedObject. Also, specify the initial capacity to avoid unnecessary reallocations. Bug: 117113131 Test: atest BroadcastRadioTests Change-Id: Ib33b97d482422b1acac8e9420a0c974bcd59355b --- core/java/android/hardware/radio/Utils.java | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/core/java/android/hardware/radio/Utils.java b/core/java/android/hardware/radio/Utils.java index 9887f7823269..dd7f5b2cb76d 100644 --- a/core/java/android/hardware/radio/Utils.java +++ b/core/java/android/hardware/radio/Utils.java @@ -47,7 +47,7 @@ final class Utils { static @NonNull Map readStringMap(@NonNull Parcel in) { int size = in.readInt(); - Map map = new HashMap<>(); + Map map = new HashMap<>(size); while (size-- > 0) { String key = in.readString(); String value = in.readString(); @@ -70,7 +70,7 @@ final class Utils { static @NonNull Map readStringIntMap(@NonNull Parcel in) { int size = in.readInt(); - Map map = new HashMap<>(); + Map map = new HashMap<>(size); while (size-- > 0) { String key = in.readString(); int value = in.readInt(); @@ -90,7 +90,7 @@ final class Utils { static Set createSet(@NonNull Parcel in, Parcelable.Creator c) { int size = in.readInt(); - Set set = new HashSet<>(); + Set set = new HashSet<>(size); while (size-- > 0) { set.add(in.readTypedObject(c)); } @@ -107,15 +107,12 @@ final class Utils { } static Set createIntSet(@NonNull Parcel in) { - return createSet(in, new Parcelable.Creator() { - public Integer createFromParcel(Parcel in) { - return in.readInt(); - } - - public Integer[] newArray(int size) { - return new Integer[size]; - } - }); + int size = in.readInt(); + Set set = new HashSet<>(size); + while (size-- > 0) { + set.add(in.readInt()); + } + return set; } static void writeTypedCollection(@NonNull Parcel dest, -- 2.11.0