From 4da2520563cf6b138cc8a7b08996ba3ed3b9181e Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Thu, 31 Oct 2019 02:49:28 -0400 Subject: [PATCH] I wonder if adding items by name to dictionary actually speeds up anything... --- .../ObjectModels/Markup/MarkupAttribute.cs | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Markup/MarkupAttribute.cs b/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Markup/MarkupAttribute.cs index 66b0677c..04ae6bfe 100644 --- a/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Markup/MarkupAttribute.cs +++ b/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Markup/MarkupAttribute.cs @@ -9,26 +9,21 @@ namespace UniversalEditor.ObjectModels.Markup public class MarkupAttributeCollection : System.Collections.ObjectModel.Collection { + private Dictionary _itemsByName = new Dictionary(); + public MarkupAttribute this[string fullName] { get { - MarkupAttribute result; - foreach (MarkupAttribute att in this) - { - if (att.FullName == fullName) - { - result = att; - return result; - } - } - result = null; - return result; + if (_itemsByName.ContainsKey(fullName)) + return _itemsByName[fullName]; + + return null; } } public MarkupAttribute Add(string fullName) { - return this.Add(fullName, string.Empty); + return Add(fullName, string.Empty); } public MarkupAttribute Add(string fullName, string value) { @@ -66,6 +61,30 @@ namespace UniversalEditor.ObjectModels.Markup } return result; } + + protected override void ClearItems() + { + base.ClearItems(); + _itemsByName.Clear(); + } + protected override void InsertItem(int index, MarkupAttribute item) + { + base.InsertItem(index, item); + _itemsByName[item.FullName] = item; + } + protected override void RemoveItem(int index) + { + if (_itemsByName.ContainsKey(this[index].FullName)) + _itemsByName.Remove(this[index].FullName); + base.RemoveItem(index); + } + protected override void SetItem(int index, MarkupAttribute item) + { + if (_itemsByName.ContainsKey(this[index].FullName)) + _itemsByName.Remove(this[index].FullName); + base.SetItem(index, item); + _itemsByName[item.Name] = item; + } } private string mvarNamespace = null; private string mvarName = string.Empty;