Revert "Don't generate OnSerialize/OnDeserialize if not needed (#199)" (#217)

This reverts commit 6eec19b205.
This commit is contained in:
Paul Pacheco 2019-01-01 09:08:39 -06:00 committed by GitHub
parent 7dc918b706
commit 40a3ecce08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -348,12 +348,6 @@ void GenerateSerialization()
return; return;
} }
if (m_SyncVars.Count == 0)
{
// nothing to sync, use base OnSerialize
return;
}
MethodDefinition serialize = new MethodDefinition("OnSerialize", MethodAttributes.Public | MethodDefinition serialize = new MethodDefinition("OnSerialize", MethodAttributes.Public |
MethodAttributes.Virtual | MethodAttributes.Virtual |
MethodAttributes.HideBySig, MethodAttributes.HideBySig,
@ -379,6 +373,15 @@ void GenerateSerialization()
serWorker.Append(serWorker.Create(OpCodes.Stloc_0)); // set dirtyLocal to result of base.OnSerialize() serWorker.Append(serWorker.Create(OpCodes.Stloc_0)); // set dirtyLocal to result of base.OnSerialize()
} }
if (m_SyncVars.Count == 0)
{
// generate: return dirtyLocal
serWorker.Append(serWorker.Create(OpCodes.Ldloc_0));
serWorker.Append(serWorker.Create(OpCodes.Ret));
m_td.Methods.Add(serialize);
return;
}
// Generates: if (forceAll); // Generates: if (forceAll);
Instruction initialStateLabel = serWorker.Create(OpCodes.Nop); Instruction initialStateLabel = serWorker.Create(OpCodes.Nop);
serWorker.Append(serWorker.Create(OpCodes.Ldarg_2)); // forceAll serWorker.Append(serWorker.Create(OpCodes.Ldarg_2)); // forceAll
@ -551,12 +554,6 @@ void GenerateDeSerialization()
return; return;
} }
if (m_SyncVars.Count == 0)
{
// nothing to sync, base OnDeserialize is fine
return;
}
MethodDefinition serialize = new MethodDefinition("OnDeserialize", MethodAttributes.Public | MethodDefinition serialize = new MethodDefinition("OnDeserialize", MethodAttributes.Public |
MethodAttributes.Virtual | MethodAttributes.Virtual |
MethodAttributes.HideBySig, MethodAttributes.HideBySig,
@ -575,6 +572,13 @@ void GenerateDeSerialization()
serWorker.Append(serWorker.Create(OpCodes.Call, baseDeserialize)); serWorker.Append(serWorker.Create(OpCodes.Call, baseDeserialize));
} }
if (m_SyncVars.Count == 0)
{
serWorker.Append(serWorker.Create(OpCodes.Ret));
m_td.Methods.Add(serialize);
return;
}
// Generates: if (initialState); // Generates: if (initialState);
Instruction initialStateLabel = serWorker.Create(OpCodes.Nop); Instruction initialStateLabel = serWorker.Create(OpCodes.Nop);