From e318947269faed98441f2985fa5814dbc170a105 Mon Sep 17 00:00:00 2001 From: AndersMalmgren Date: Thu, 6 Mar 2014 19:46:00 +0100 Subject: [PATCH] Fixed performance issues for PrepareScript --- FreePIE.Core/ScriptEngine/Globals/GlobalsInfo.cs | 15 ++++++++++++--- .../ScriptEngine/Python/PythonScriptParser.cs | 3 ++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/FreePIE.Core/ScriptEngine/Globals/GlobalsInfo.cs b/FreePIE.Core/ScriptEngine/Globals/GlobalsInfo.cs index 7679c7e7..1506b91b 100644 --- a/FreePIE.Core/ScriptEngine/Globals/GlobalsInfo.cs +++ b/FreePIE.Core/ScriptEngine/Globals/GlobalsInfo.cs @@ -8,6 +8,8 @@ namespace FreePIE.Core.ScriptEngine.Globals { public static class GlobalsInfo { + private static readonly Dictionary globalNamesCache = new Dictionary(); + public static string GetGlobalName(object global) { var name = GetGlobalName(global.GetType()); @@ -22,10 +24,17 @@ public static string GetGlobalName(object global) public static string GetGlobalName(Type type) { - var typeAttribute = GetAttribute(type); - var globalAttribute = typeAttribute != null ? GetAttribute(typeAttribute.Type) : GetAttribute(type); + if (!globalNamesCache.ContainsKey(type)) + { + var typeAttribute = GetAttribute(type); + var globalAttribute = typeAttribute != null + ? GetAttribute(typeAttribute.Type) + : GetAttribute(type); + + globalNamesCache[type] = globalAttribute != null ? globalAttribute.Name : null; + } - return globalAttribute != null ? globalAttribute.Name : null; + return globalNamesCache[type]; } public static IEnumerable GetGlobalMembers(Type pluginType) diff --git a/FreePIE.Core/ScriptEngine/Python/PythonScriptParser.cs b/FreePIE.Core/ScriptEngine/Python/PythonScriptParser.cs index 02d273b1..f979c95e 100644 --- a/FreePIE.Core/ScriptEngine/Python/PythonScriptParser.cs +++ b/FreePIE.Core/ScriptEngine/Python/PythonScriptParser.cs @@ -109,7 +109,8 @@ private string FindAndInitMethodsThatNeedIndexer(string script, IEnumerable g.GetType().GetMethods() .Where(m => m.GetCustomAttributes(typeof(NeedIndexer), false).Length > 0) - .Select(m => new { Global = g, MethodInfo = m })); + .Select(m => new { Global = g, MethodInfo = m })) + .ToList(); for (int i = 0; i < script.Length; i++) {