From c7debc2346156ca559341c0860e6aa60af50c938 Mon Sep 17 00:00:00 2001 From: Simon Rodriguez Date: Sun, 27 Nov 2022 15:07:37 +0100 Subject: [PATCH] Added ifdef 2021_3_or_newer where Unity upgraded to net standard 2.1 where Dictionary.EnsureCapacity is added. --- Scripts/Node.cs | 2 ++ Scripts/NodeDataCache.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Scripts/Node.cs b/Scripts/Node.cs index 93396bf..62a2f4a 100644 --- a/Scripts/Node.cs +++ b/Scripts/Node.cs @@ -406,7 +406,9 @@ namespace XNode { public void OnAfterDeserialize() { this.Clear(); +#if UNITY_2021_3_OR_NEWER this.EnsureCapacity(keys.Count); +#endif if (keys.Count != values.Count) throw new System.Exception("there are " + keys.Count + " keys and " + values.Count + " values after deserialization. Make sure that both key and value types are serializable."); diff --git a/Scripts/NodeDataCache.cs b/Scripts/NodeDataCache.cs index 08ac91b..32906a6 100644 --- a/Scripts/NodeDataCache.cs +++ b/Scripts/NodeDataCache.cs @@ -37,7 +37,9 @@ namespace XNode { List typePortCache; if (portDataCache.TryGetValue(nodeType, out typePortCache)) { +#if UNITY_2021_3_OR_NEWER staticPorts.EnsureCapacity(typePortCache.Count); +#endif for (int i = 0; i < typePortCache.Count; i++) { staticPorts.Add(typePortCache[i].fieldName, typePortCache[i]); }