From 6fae01a4fdb1e29ae56a2a5252059dfbbac876de Mon Sep 17 00:00:00 2001 From: Nicolas Gnyra Date: Sun, 7 Jan 2024 22:04:33 -0500 Subject: [PATCH] Don't repeatedly access `Attributes` --- BeatSaberMarkupLanguage/BSMLParser.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/BeatSaberMarkupLanguage/BSMLParser.cs b/BeatSaberMarkupLanguage/BSMLParser.cs index fbdd35dd..4fd494aa 100644 --- a/BeatSaberMarkupLanguage/BSMLParser.cs +++ b/BeatSaberMarkupLanguage/BSMLParser.cs @@ -288,7 +288,7 @@ public void HandleNode(XmlNode node, GameObject parent, BSMLParserParams parserP private void HandleTagNode(XmlNode node, GameObject parent, BSMLParserParams parserParams, out IEnumerable componentInfo) { - if (!tags.TryGetValue(node.Name, out BSMLTag currentTag)) + if (!this.tags.TryGetValue(node.Name, out BSMLTag currentTag)) { throw new TagNotFoundException(node.Name); } @@ -322,25 +322,27 @@ private void HandleTagNode(XmlNode node, GameObject parent, BSMLParserParams par } object host = parserParams.host; - if (host != null && node.Attributes["id"] != null) + XmlAttribute id = node.Attributes["id"]; + if (host != null && id != null) { foreach (FieldInfo fieldInfo in host.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)) { - if (fieldInfo.GetCustomAttribute(true)?.id == node.Attributes["id"].Value) + if (fieldInfo.GetCustomAttribute(true)?.id == id.Value) { fieldInfo.SetValue(host, GetExternalComponent(currentNode, fieldInfo.FieldType)); } - if (fieldInfo.GetCustomAttribute(true)?.id == node.Attributes["id"].Value) + if (fieldInfo.GetCustomAttribute(true)?.id == id.Value) { fieldInfo.SetValue(host, currentNode); } } } - if (node.Attributes["tags"] != null) + XmlAttribute tags = node.Attributes["tags"]; + if (tags != null) { - parserParams.AddObjectTags(currentNode, node.Attributes["tags"].Value.Split(',')); + parserParams.AddObjectTags(currentNode, tags.Value.Split(',')); } IEnumerable childrenComponents = Enumerable.Empty(); @@ -410,9 +412,10 @@ private Dictionary GetParameters(XmlNode node, Dictionary