mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 01:06:01 +08:00
cache the AssemblyQualifiedName string, reduces number of allocations and garbage collection in projects with many nodes
This commit is contained in:
parent
f0b7882f6e
commit
a077ca136b
@ -8,8 +8,20 @@ namespace XNode {
|
||||
public static class NodeDataCache {
|
||||
private static PortDataCache portDataCache;
|
||||
private static Dictionary<System.Type, Dictionary<string, string>> formerlySerializedAsCache;
|
||||
private static Dictionary<System.Type, string> typeQualifiedNameCache;
|
||||
private static bool Initialized { get { return portDataCache != null; } }
|
||||
|
||||
public static string GetTypeQualifiedName(System.Type type) {
|
||||
if(typeQualifiedNameCache == null) typeQualifiedNameCache = new Dictionary<System.Type, string>();
|
||||
|
||||
string name;
|
||||
if (!typeQualifiedNameCache.TryGetValue(type, out name)) {
|
||||
name = type.AssemblyQualifiedName;
|
||||
typeQualifiedNameCache.Add(type, name);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/// <summary> Update static ports and dynamic ports managed by DynamicPortLists to reflect class fields. </summary>
|
||||
public static void UpdatePorts(Node node, Dictionary<string, NodePort> ports) {
|
||||
if (!Initialized) BuildCache();
|
||||
|
||||
@ -48,7 +48,7 @@ namespace XNode {
|
||||
}
|
||||
set {
|
||||
valueType = value;
|
||||
if (value != null) _typeQualifiedName = value.AssemblyQualifiedName;
|
||||
if (value != null) _typeQualifiedName = NodeDataCache.GetTypeQualifiedName(value);
|
||||
}
|
||||
}
|
||||
private Type valueType;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user