From 561d64e5bfd549c05b65c7bad87362bc03607363 Mon Sep 17 00:00:00 2001 From: Chenj168 <62330325+Chenj168@users.noreply.github.com> Date: Fri, 20 Mar 2020 07:11:20 +0900 Subject: [PATCH] Modify TranslatedFunction.GetPointer () to optimize performance (#995) * add local var to reduce calling Marshal.GetFunctionPointerForDelegate * modify code style --- ARMeilleure/Translation/TranslatedFunction.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ARMeilleure/Translation/TranslatedFunction.cs b/ARMeilleure/Translation/TranslatedFunction.cs index af01aaab31..f1dc6deeb0 100644 --- a/ARMeilleure/Translation/TranslatedFunction.cs +++ b/ARMeilleure/Translation/TranslatedFunction.cs @@ -9,6 +9,7 @@ namespace ARMeilleure.Translation private const int MinCallsForRejit = 100; private GuestFunction _func; + private IntPtr _funcPtr; private bool _rejit; private int _callCount; @@ -33,7 +34,12 @@ namespace ARMeilleure.Translation public IntPtr GetPointer() { - return Marshal.GetFunctionPointerForDelegate(_func); + if (_funcPtr == IntPtr.Zero) + { + _funcPtr = Marshal.GetFunctionPointerForDelegate(_func); + } + + return _funcPtr; } } } \ No newline at end of file