From d3c85695f2629641a492c6af7a1e54573172ecc4 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Wed, 25 Mar 2020 02:07:34 -0500 Subject: [PATCH] Added more cases where value type copies are skipped --- .../Stores/GeneratedStoreImpl/Correction.cs | 17 +++++++++++++++++ .../Stores/GeneratedStoreImpl/MakeCreator.cs | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/IPA.Loader/Config/Stores/GeneratedStoreImpl/Correction.cs b/IPA.Loader/Config/Stores/GeneratedStoreImpl/Correction.cs index 94a989a9..127d7c65 100644 --- a/IPA.Loader/Config/Stores/GeneratedStoreImpl/Correction.cs +++ b/IPA.Loader/Config/Stores/GeneratedStoreImpl/Correction.cs @@ -27,7 +27,13 @@ namespace IPA.Config.Stores var expectType = GetExpectedValueTypeForType(memberType); if (expectType == typeof(Map)) // TODO: make this slightly saner + { + if (expectType.IsValueType) + { // custom value type + return ReadObjectMembers(memberType).Any(NeedsCorrection); + } return true; + } return false; } @@ -86,6 +92,17 @@ namespace IPA.Config.Stores var valueLocal = GetLocal(convType); il.Emit(OpCodes.Stloc, valueLocal); + void LdlocaValueLocal(ILGenerator il) + => il.Emit(OpCodes.Ldloca, valueLocal); + + foreach (var mem in structure) + { + if (NeedsCorrection(mem)) + EmitLoadCorrectStore(il, mem, shouldLock, alwaysNew, GetLocal, + LdlocaValueLocal, LdlocaValueLocal, parentobj); + } + + il.Emit(OpCodes.Ldloc, valueLocal); } if (member.IsNullable) diff --git a/IPA.Loader/Config/Stores/GeneratedStoreImpl/MakeCreator.cs b/IPA.Loader/Config/Stores/GeneratedStoreImpl/MakeCreator.cs index 00ec352b..3b584f15 100644 --- a/IPA.Loader/Config/Stores/GeneratedStoreImpl/MakeCreator.cs +++ b/IPA.Loader/Config/Stores/GeneratedStoreImpl/MakeCreator.cs @@ -124,7 +124,8 @@ namespace IPA.Config.Stores foreach (var member in structure) { - EmitLoadCorrectStore(il, member, false, true, GetLocal, GetMethodThis, GetMethodThis, GetMethodThis); + if (NeedsCorrection(member)) + EmitLoadCorrectStore(il, member, false, true, GetLocal, GetMethodThis, GetMethodThis, GetMethodThis); } il.Emit(OpCodes.Pop);