From 216332ff5320cf08727f8a92c891eef145648f92 Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Wed, 22 Dec 2021 11:38:37 +0100 Subject: [PATCH] Add caching for code docs in Editor --- .../SourceCodeEditing/CodeDocsModule.cs | 47 ++++++++++++++++--- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/Source/Editor/Modules/SourceCodeEditing/CodeDocsModule.cs b/Source/Editor/Modules/SourceCodeEditing/CodeDocsModule.cs index d8a5cc0a2..6270b3e6a 100644 --- a/Source/Editor/Modules/SourceCodeEditing/CodeDocsModule.cs +++ b/Source/Editor/Modules/SourceCodeEditing/CodeDocsModule.cs @@ -1,5 +1,6 @@ // Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. +using System.Collections.Generic; using System.Linq; using FlaxEditor.Scripting; using FlaxEngine; @@ -12,6 +13,9 @@ namespace FlaxEditor.Modules.SourceCodeEditing /// public sealed class CodeDocsModule : EditorModule { + private Dictionary _typeCache = new Dictionary(); + private Dictionary _memberCache = new Dictionary(); + internal CodeDocsModule(Editor editor) : base(editor) { @@ -25,30 +29,59 @@ namespace FlaxEditor.Modules.SourceCodeEditing /// The documentation tooltip. public string GetTooltip(ScriptType type, object[] attributes = null) { + if (_typeCache.TryGetValue(type, out var text)) + return text; + if (attributes == null) attributes = type.GetAttributes(false); - var text = type.TypeName; + text = type.TypeName; var tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute); if (tooltip != null) text += '\n' + tooltip.Text; + _typeCache.Add(type, text); return text; } /// - /// Gets the tooltip text for the type. + /// Gets the tooltip text for the type member. /// - /// The type. - /// The type attributes. Optional, if null type attributes will be used. + /// The type member. + /// The member attributes. Optional, if null member attributes will be used. /// The documentation tooltip. - public string GetTooltip(ScriptMemberInfo type, object[] attributes = null) + public string GetTooltip(ScriptMemberInfo member, object[] attributes = null) { + if (_memberCache.TryGetValue(member, out var text)) + return text; + if (attributes == null) - attributes = type.GetAttributes(true); - string text = null; + attributes = member.GetAttributes(true); var tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute); if (tooltip != null) text = tooltip.Text; + _memberCache.Add(member, text); return text; } + + /// + public override void OnInit() + { + base.OnInit(); + + Editor.CodeEditing.TypesCleared += OnTypesCleared; + } + + private void OnTypesCleared() + { + _typeCache.Clear(); + _memberCache.Clear(); + } + + /// + public override void OnExit() + { + OnTypesCleared(); + + base.OnExit(); + } } }