Parcelable: Use specialized write/create methods where available (KT-20057)
This commit is contained in:
committed by
Yan Zhulanow
parent
f6d7a17227
commit
1b688182cd
+20
-2
@@ -72,6 +72,12 @@ interface ParcelSerializer {
|
|||||||
|| asmType.descriptor == "[F"
|
|| asmType.descriptor == "[F"
|
||||||
|| asmType.descriptor == "[L" -> PrimitiveArrayParcelSerializer(asmType)
|
|| asmType.descriptor == "[L" -> PrimitiveArrayParcelSerializer(asmType)
|
||||||
|
|
||||||
|
asmType.descriptor == "[Landroid/os/IBinder;" -> NullCompliantObjectParcelSerializer(asmType,
|
||||||
|
Method("writeBinderArray"), Method("createBinderArray"))
|
||||||
|
|
||||||
|
asmType.descriptor == "[Ljava/lang/String;" -> NullCompliantObjectParcelSerializer(asmType,
|
||||||
|
Method("writeStringArray"), Method("createStringArray"))
|
||||||
|
|
||||||
asmType.sort == Type.ARRAY -> {
|
asmType.sort == Type.ARRAY -> {
|
||||||
val elementType = type.builtIns.getArrayElementType(type)
|
val elementType = type.builtIns.getArrayElementType(type)
|
||||||
val elementSerializer = get(elementType, typeMapper.mapTypeSafe(elementType), context, strict = strict())
|
val elementSerializer = get(elementType, typeMapper.mapTypeSafe(elementType), context, strict = strict())
|
||||||
@@ -101,8 +107,20 @@ interface ParcelSerializer {
|
|||||||
|| className == TreeSet::class.java.canonicalName
|
|| className == TreeSet::class.java.canonicalName
|
||||||
-> {
|
-> {
|
||||||
val elementType = type.arguments.single().type
|
val elementType = type.arguments.single().type
|
||||||
val elementSerializer = get(
|
val elementAsmType = typeMapper.mapTypeSafe(elementType)
|
||||||
elementType, typeMapper.mapTypeSafe(elementType), context, forceBoxed = true, strict = strict())
|
|
||||||
|
if (className == List::class.java.canonicalName) {
|
||||||
|
// Don't care if the element type is nullable cause both writeStrongBinder() and writeString() support null values
|
||||||
|
if (elementAsmType.descriptor == "Landroid/os/IBinder;") {
|
||||||
|
return NullCompliantObjectParcelSerializer(asmType,
|
||||||
|
Method("writeBinderList"), Method("createBinderArrayList", "()Ljava/util/ArrayList;"))
|
||||||
|
} else if (elementAsmType.descriptor == "Ljava/lang/String;") {
|
||||||
|
return NullCompliantObjectParcelSerializer(asmType,
|
||||||
|
Method("writeStringList"), Method("createStringArrayList", "()Ljava/util/ArrayList;"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val elementSerializer = get(elementType, elementAsmType, context, forceBoxed = true, strict = strict())
|
||||||
wrapToNullAwareIfNeeded(type, ListSetParcelSerializer(asmType, elementSerializer))
|
wrapToNullAwareIfNeeded(type, ListSetParcelSerializer(asmType, elementSerializer))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+7
-1
@@ -7,4 +7,10 @@ import android.os.IBinder
|
|||||||
import android.os.IInterface
|
import android.os.IInterface
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
class User(val binder: IBinder, val intf: IInterface?) : Parcelable
|
class User(
|
||||||
|
val binder: IBinder,
|
||||||
|
val binderArray: Array<IBinder>,
|
||||||
|
val binderList: List<IBinder>,
|
||||||
|
val binderArrayList: ArrayList<IBinder>, // should be serialized using our strategy, not using Parcel.writeBinderList()
|
||||||
|
val intf: IInterface?
|
||||||
|
) : Parcelable
|
||||||
plugins/android-extensions/android-extensions-compiler/testData/parcel/codegen/IBinderIInterface.txt
Vendored
+74
-4
@@ -6,15 +6,45 @@ public final class User$Creator : java/lang/Object, android/os/Parcelable$Creato
|
|||||||
ALOAD (1)
|
ALOAD (1)
|
||||||
LDC (in)
|
LDC (in)
|
||||||
INVOKESTATIC (kotlin/jvm/internal/Intrinsics, checkParameterIsNotNull, (Ljava/lang/Object;Ljava/lang/String;)V)
|
INVOKESTATIC (kotlin/jvm/internal/Intrinsics, checkParameterIsNotNull, (Ljava/lang/Object;Ljava/lang/String;)V)
|
||||||
|
LABEL (L1)
|
||||||
NEW
|
NEW
|
||||||
DUP
|
DUP
|
||||||
ALOAD (1)
|
ALOAD (1)
|
||||||
INVOKEVIRTUAL (android/os/Parcel, readStrongBinder, ()Landroid/os/IBinder;)
|
INVOKEVIRTUAL (android/os/Parcel, readStrongBinder, ()Landroid/os/IBinder;)
|
||||||
ALOAD (1)
|
ALOAD (1)
|
||||||
|
INVOKEVIRTUAL (android/os/Parcel, createBinderArray, ()[Landroid/os/IBinder;)
|
||||||
|
ALOAD (1)
|
||||||
|
INVOKEVIRTUAL (android/os/Parcel, createBinderArrayList, ()Ljava/util/ArrayList;)
|
||||||
|
CHECKCAST
|
||||||
|
ALOAD (1)
|
||||||
|
INVOKEVIRTUAL (android/os/Parcel, readInt, ()I)
|
||||||
|
DUP
|
||||||
|
NEW
|
||||||
|
DUP_X1
|
||||||
|
SWAP
|
||||||
|
INVOKESPECIAL (java/util/ArrayList, <init>, (I)V)
|
||||||
|
LABEL (L2)
|
||||||
|
SWAP
|
||||||
|
DUP_X1
|
||||||
|
IFEQ (L3)
|
||||||
|
DUP
|
||||||
|
ALOAD (1)
|
||||||
|
INVOKEVIRTUAL (android/os/Parcel, readStrongBinder, ()Landroid/os/IBinder;)
|
||||||
|
INVOKEVIRTUAL (java/util/ArrayList, add, (Ljava/lang/Object;)Z)
|
||||||
|
POP
|
||||||
|
SWAP
|
||||||
|
LDC (-1)
|
||||||
|
IADD
|
||||||
|
SWAP
|
||||||
|
GOTO (L2)
|
||||||
|
LABEL (L3)
|
||||||
|
SWAP
|
||||||
|
POP
|
||||||
|
ALOAD (1)
|
||||||
INVOKEVIRTUAL (android/os/Parcel, readStrongInterface, ()Landroid/os/IInterface;)
|
INVOKEVIRTUAL (android/os/Parcel, readStrongInterface, ()Landroid/os/IInterface;)
|
||||||
INVOKESPECIAL (User, <init>, (Landroid/os/IBinder;Landroid/os/IInterface;)V)
|
INVOKESPECIAL (User, <init>, (Landroid/os/IBinder;[Landroid/os/IBinder;Ljava/util/List;Ljava/util/ArrayList;Landroid/os/IInterface;)V)
|
||||||
ARETURN
|
ARETURN
|
||||||
LABEL (L1)
|
LABEL (L4)
|
||||||
}
|
}
|
||||||
|
|
||||||
public final User[] newArray(int p0)
|
public final User[] newArray(int p0)
|
||||||
@@ -25,16 +55,28 @@ public final class User : java/lang/Object, android/os/Parcelable {
|
|||||||
|
|
||||||
private final android.os.IBinder binder
|
private final android.os.IBinder binder
|
||||||
|
|
||||||
|
private final android.os.IBinder[] binderArray
|
||||||
|
|
||||||
|
private final java.util.ArrayList binderArrayList
|
||||||
|
|
||||||
|
private final java.util.List binderList
|
||||||
|
|
||||||
private final android.os.IInterface intf
|
private final android.os.IInterface intf
|
||||||
|
|
||||||
static void <clinit>()
|
static void <clinit>()
|
||||||
|
|
||||||
public void <init>(android.os.IBinder p0, android.os.IInterface p1)
|
public void <init>(android.os.IBinder p0, android.os.IBinder[] p1, java.util.List p2, java.util.ArrayList p3, android.os.IInterface p4)
|
||||||
|
|
||||||
public final int describeContents()
|
public final int describeContents()
|
||||||
|
|
||||||
public final android.os.IBinder getBinder()
|
public final android.os.IBinder getBinder()
|
||||||
|
|
||||||
|
public final android.os.IBinder[] getBinderArray()
|
||||||
|
|
||||||
|
public final java.util.ArrayList getBinderArrayList()
|
||||||
|
|
||||||
|
public final java.util.List getBinderList()
|
||||||
|
|
||||||
public final android.os.IInterface getIntf()
|
public final android.os.IInterface getIntf()
|
||||||
|
|
||||||
public final void writeToParcel(android.os.Parcel p0, int p1) {
|
public final void writeToParcel(android.os.Parcel p0, int p1) {
|
||||||
@@ -48,9 +90,37 @@ public final class User : java/lang/Object, android/os/Parcelable {
|
|||||||
INVOKEVIRTUAL (android/os/Parcel, writeStrongBinder, (Landroid/os/IBinder;)V)
|
INVOKEVIRTUAL (android/os/Parcel, writeStrongBinder, (Landroid/os/IBinder;)V)
|
||||||
ALOAD (1)
|
ALOAD (1)
|
||||||
ALOAD (0)
|
ALOAD (0)
|
||||||
|
GETFIELD (binderArray, [Landroid/os/IBinder;)
|
||||||
|
INVOKEVIRTUAL (android/os/Parcel, writeBinderArray, ([Landroid/os/IBinder;)V)
|
||||||
|
ALOAD (1)
|
||||||
|
ALOAD (0)
|
||||||
|
GETFIELD (binderList, Ljava/util/List;)
|
||||||
|
INVOKEVIRTUAL (android/os/Parcel, writeBinderList, (Ljava/util/List;)V)
|
||||||
|
ALOAD (1)
|
||||||
|
ALOAD (0)
|
||||||
|
GETFIELD (binderArrayList, Ljava/util/ArrayList;)
|
||||||
|
DUP_X1
|
||||||
|
INVOKEINTERFACE (java/util/Collection, size, ()I)
|
||||||
|
INVOKEVIRTUAL (android/os/Parcel, writeInt, (I)V)
|
||||||
|
INVOKEINTERFACE (java/util/Collection, iterator, ()Ljava/util/Iterator;)
|
||||||
|
LABEL (L1)
|
||||||
|
DUP
|
||||||
|
INVOKEINTERFACE (java/util/Iterator, hasNext, ()Z)
|
||||||
|
IFEQ (L2)
|
||||||
|
DUP
|
||||||
|
ALOAD (1)
|
||||||
|
SWAP
|
||||||
|
INVOKEINTERFACE (java/util/Iterator, next, ()Ljava/lang/Object;)
|
||||||
|
CHECKCAST
|
||||||
|
INVOKEVIRTUAL (android/os/Parcel, writeStrongBinder, (Landroid/os/IBinder;)V)
|
||||||
|
GOTO (L1)
|
||||||
|
LABEL (L2)
|
||||||
|
POP
|
||||||
|
ALOAD (1)
|
||||||
|
ALOAD (0)
|
||||||
GETFIELD (intf, Landroid/os/IInterface;)
|
GETFIELD (intf, Landroid/os/IInterface;)
|
||||||
INVOKEVIRTUAL (android/os/Parcel, writeStrongInterface, (Landroid/os/IInterface;)V)
|
INVOKEVIRTUAL (android/os/Parcel, writeStrongInterface, (Landroid/os/IInterface;)V)
|
||||||
RETURN
|
RETURN
|
||||||
LABEL (L1)
|
LABEL (L3)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -4,4 +4,4 @@
|
|||||||
import kotlinx.android.parcel.*
|
import kotlinx.android.parcel.*
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
class Test(val names: List<List<List<String>>>)
|
class Test(val names: List<List<ArrayList<String>>>)
|
||||||
Vendored
+2
-18
@@ -27,24 +27,8 @@ public final class Test : java/lang/Object {
|
|||||||
ALOAD (1)
|
ALOAD (1)
|
||||||
ALOAD (0)
|
ALOAD (0)
|
||||||
GETFIELD (names, Ljava/util/List;)
|
GETFIELD (names, Ljava/util/List;)
|
||||||
DUP_X1
|
INVOKEVIRTUAL (android/os/Parcel, writeStringList, (Ljava/util/List;)V)
|
||||||
INVOKEINTERFACE (java/util/Collection, size, ()I)
|
|
||||||
INVOKEVIRTUAL (android/os/Parcel, writeInt, (I)V)
|
|
||||||
INVOKEINTERFACE (java/util/Collection, iterator, ()Ljava/util/Iterator;)
|
|
||||||
LABEL (L1)
|
|
||||||
DUP
|
|
||||||
INVOKEINTERFACE (java/util/Iterator, hasNext, ()Z)
|
|
||||||
IFEQ (L2)
|
|
||||||
DUP
|
|
||||||
ALOAD (1)
|
|
||||||
SWAP
|
|
||||||
INVOKEINTERFACE (java/util/Iterator, next, ()Ljava/lang/Object;)
|
|
||||||
CHECKCAST
|
|
||||||
INVOKEVIRTUAL (android/os/Parcel, writeString, (Ljava/lang/String;)V)
|
|
||||||
GOTO (L1)
|
|
||||||
LABEL (L2)
|
|
||||||
POP
|
|
||||||
RETURN
|
RETURN
|
||||||
LABEL (L3)
|
LABEL (L1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user