reuse ReadLength (#2292)

This commit is contained in:
Paul Pacheco 2020-09-28 21:32:16 -05:00 committed by GitHub
parent 7c2a6595eb
commit 66be588512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -132,9 +132,7 @@ static MethodDefinition GenerateArrayReadFunc(TypeReference variable)
ILProcessor worker = readerFunc.Body.GetILProcessor();
// int length = reader.ReadPackedInt32();
worker.Append(worker.Create(OpCodes.Ldarg_0));
worker.Append(worker.Create(OpCodes.Call, GetReadFunc(WeaverTypes.Import<int>())));
worker.Append(worker.Create(OpCodes.Stloc_0));
GenerateReadLength(worker);
// if (length < 0) {
// return null
@ -172,6 +170,13 @@ static MethodDefinition GenerateArrayReadFunc(TypeReference variable)
return readerFunc;
}
private static void GenerateReadLength(ILProcessor worker)
{
worker.Append(worker.Create(OpCodes.Ldarg_0));
worker.Append(worker.Create(OpCodes.Call, GetReadFunc(WeaverTypes.Import<int>())));
worker.Append(worker.Create(OpCodes.Stloc_0));
}
static MethodDefinition GenerateEnumReadFunc(TypeReference variable)
{
MethodDefinition readerFunc = GenerateReaderFunction(variable);
@ -212,9 +217,7 @@ static MethodDefinition GenerateArraySegmentReadFunc(TypeReference variable)
ILProcessor worker = readerFunc.Body.GetILProcessor();
// int length = reader.ReadPackedInt32();
worker.Append(worker.Create(OpCodes.Ldarg_0));
worker.Append(worker.Create(OpCodes.Call, GetReadFunc(WeaverTypes.Import<int>())));
worker.Append(worker.Create(OpCodes.Stloc_0));
GenerateReadLength(worker);
// T[] array = new int[length]
worker.Append(worker.Create(OpCodes.Ldloc_0));
@ -312,10 +315,8 @@ static MethodDefinition GenerateListReadFunc(TypeReference variable)
ILProcessor worker = readerFunc.Body.GetILProcessor();
// int count = reader.ReadPackedInt32();
worker.Append(worker.Create(OpCodes.Ldarg_0));
worker.Append(worker.Create(OpCodes.Call, GetReadFunc(WeaverTypes.Import<int>())));
worker.Append(worker.Create(OpCodes.Stloc_0));
// int length = reader.ReadPackedInt32();
GenerateReadLength(worker);
// -1 is null list, so if count is less than 0 return null
// if (count < 0) {